Documentation ¶
Index ¶
- type CustomClaims
- type ICustomClaims
- type IVerifier
- type MockVerifier
- func (m *MockVerifier) Verify(w http.ResponseWriter, r *http.Request, groups []string) (*CustomClaims, error)
- func (m *MockVerifier) VerifyTokenWithCustomClaims(r *http.Request, authToken string, groups []string, claims ICustomClaims) (ICustomClaims, error)
- func (m *MockVerifier) VerifyWithCustomClaims(w http.ResponseWriter, r *http.Request, groups []string, claims ICustomClaims) (ICustomClaims, error)
- type Verifier
- func (j *Verifier) Verify(w http.ResponseWriter, r *http.Request, groups []string) (*CustomClaims, error)
- func (j *Verifier) VerifyTokenWithCustomClaims(r *http.Request, authToken string, groups []string, claims ICustomClaims) (ICustomClaims, error)
- func (j *Verifier) VerifyWithCustomClaims(w http.ResponseWriter, r *http.Request, groups []string, claims ICustomClaims) (ICustomClaims, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CustomClaims ¶
type CustomClaims struct { jwt.RegisteredClaims UserID int64 `json:"user_id"` Groups []string `json:"groups"` }
CustomClaims definies the format of the JWT payload
func (*CustomClaims) GetAudiences ¶
func (j *CustomClaims) GetAudiences() []string
GetAudiences returns the audiences
func (*CustomClaims) GetGroups ¶
func (j *CustomClaims) GetGroups() []string
GetGroups returns all Groups
func (*CustomClaims) GetUserID ¶
func (j *CustomClaims) GetUserID() int64
GetUserID returns the UserID
type ICustomClaims ¶
type ICustomClaims interface { jwt.Claims GetUserID() int64 GetGroups() []string GetAudiences() []string }
ICustomClaims definies the generic interface for custom jwt claims
type IVerifier ¶
type IVerifier interface { Verify(w http.ResponseWriter, r *http.Request, groups []string) (*CustomClaims, error) VerifyWithCustomClaims(w http.ResponseWriter, r *http.Request, groups []string, claims ICustomClaims) (ICustomClaims, error) VerifyTokenWithCustomClaims(r *http.Request, authToken string, groups []string, claims ICustomClaims) (ICustomClaims, error) }
IJWTVerifier defines the interface of JWTVerifier
type MockVerifier ¶
type MockVerifier struct { VerifyFunc func(w http.ResponseWriter, r *http.Request, groups []string) (*CustomClaims, error) VerifyFuncCalled int VerifyWithCustomClaimsFunc func(w http.ResponseWriter, r *http.Request, groups []string, claims ICustomClaims) (ICustomClaims, error) VerifyWithCustomClaimsFuncCalled int VerifyTokenWithCustomClaimsFunc func(r *http.Request, authToken string, groups []string, claims ICustomClaims) (ICustomClaims, error) VerifyTokenWithCustomClaimsFuncCalled int }
MockVerifier provides a simple mock for JWTVerifier
func NewMockVerifier ¶
func NewMockVerifier() *MockVerifier
NewMockVerifier creates a new initialized instance of MockVerifier
func (*MockVerifier) Verify ¶
func (m *MockVerifier) Verify(w http.ResponseWriter, r *http.Request, groups []string) (*CustomClaims, error)
Verify calls VerifyFunc and increases VerifyFuncCalled
func (*MockVerifier) VerifyTokenWithCustomClaims ¶
func (m *MockVerifier) VerifyTokenWithCustomClaims(r *http.Request, authToken string, groups []string, claims ICustomClaims) (ICustomClaims, error)
VerifyWithCustomClaims calls VerifyTokenWithCustomClaimsFunc and increases VerifyTokenWithCustomClaimsFuncCalled
func (*MockVerifier) VerifyWithCustomClaims ¶
func (m *MockVerifier) VerifyWithCustomClaims(w http.ResponseWriter, r *http.Request, groups []string, claims ICustomClaims) (ICustomClaims, error)
VerifyWithCustomClaims calls VerifyWithCustomClaimsFunc and increases VerifyWithCustomClaimsFuncCalled
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
JWTVerifier provides a simple JWT verification utility
Used flags:
- jwt_publickey Filename of JWT-Public-Key-File ()
func NewVerifier ¶
NewVerifier creates a new initilized instance of JWTVerifier and loads the public key from the file specified by the flag 'jwt_publickey'
func (*Verifier) Verify ¶
func (j *Verifier) Verify(w http.ResponseWriter, r *http.Request, groups []string) (*CustomClaims, error)
Verify validates the JWT from the authorization header and checks if the required groups are fullfiled
If the authorization fails it sends a 403 and returns
func (*Verifier) VerifyTokenWithCustomClaims ¶
func (j *Verifier) VerifyTokenWithCustomClaims(r *http.Request, authToken string, groups []string, claims ICustomClaims) (ICustomClaims, error)
VerifyTokenWithCustomClaims validates a JWT and checks if the required groups are fullfiled
If the authorization fails it sends a 403 and returns
func (*Verifier) VerifyWithCustomClaims ¶
func (j *Verifier) VerifyWithCustomClaims(w http.ResponseWriter, r *http.Request, groups []string, claims ICustomClaims) (ICustomClaims, error)
VerifyWithCustomClaims validates the JWT from the authorization header and checks if the required groups are fullfiled
If the authorization fails it sends a 403 and returns