Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessToken ¶
type AccessToken struct {
Token string `json:"access_token"`
Type string `json:"token_type"`
Expires int64 `json:"expires_in"`
}
AccessToken represents an access token.
func (*AccessToken) Marshal ¶
func (t *AccessToken) Marshal() string
Marshal marshals the AccessToken to a JSON string.
type Claims ¶
type Claims struct {
jwt.StandardClaims
Username string `json:"user"`
Role repository.UserRole `json:"role"`
}
Claims is the custom JWT claims container.
type JWTGenerator ¶
type JWTGenerator struct {
Keys *Keys
SigningMethod jwt.SigningMethod
}
JWTGenerator generates an AccessToken.
func NewJWTGenerator ¶
func NewJWTGenerator(keys *Keys, signingMethod jwt.SigningMethod) *JWTGenerator
NewJWTGenerator returns a new instance of JWTGenerator.
func (*JWTGenerator) Generate ¶
func (gen *JWTGenerator) Generate(username string, role repository.UserRole) (*AccessToken, error)
Generate generates an AccessToken using the username and role claims.
type JWTValidator ¶
type JWTValidator struct {
// contains filtered or unexported fields
}
JWTValidator validates and authorizes an AccessToken.
func NewJWTValidator ¶
func NewJWTValidator(key *Keys, repo repository.Repository) *JWTValidator
NewJWTValidator returns a new instance of JWTValidator.
func (*JWTValidator) Authorize ¶
func (val *JWTValidator) Authorize(token string, request *repository.RequestDetails) bool
Authorize validates the token and authorizes the actual request.
type Keys ¶
type Keys struct {
PrivateKey *rsa.PrivateKey
PublicKey *rsa.PublicKey
}
Keys represents a container for the private and public keys.
func NewKeysFromFile ¶
NewKeysFromFile creates and returns a new instance of Keys from the files.
type TokenType ¶
type TokenType int
TokenType represents a token type.
const ( // BearerToken is an opaque string, not intended to have any meaning to clients using it. // Some servers will issue tokens that are a short `string` of hexadecimal characters, // while others may use structured tokens such as JSON Web Tokens. BearerToken TokenType = iota // BasicToken is a string where credentials is the base64 encoding of id and // password joined by a single colon : BasicToken )