Documentation ¶
Overview ¶
Thanks to https://github.com/adam-hanna/jwt-auth. This package is inspired by it. Package jwt provides JWT-based authentication function.
Index ¶
- Variables
- func SetSigningMethod(method string) Jwt.SigningMethod
- type JWTClaims
- type Options
- type Store
- type Token
- func (t *Token) Authenticator() gin.HandlerFunc
- func (t *Token) CheckToken(token string) (*UserInfo, error)
- func (t *Token) GenerateToken(id string, data map[string]interface{}) (string, error)
- func (t *Token) GetToken(r *http.Request) (string, error)
- func (t *Token) GetTokenData(token string) (map[string]interface{}, error)
- func (t *Token) RevokeToken(id string) error
- func (t *Token) ValidateToken(token string) (*TokenInfo, error)
- type TokenInfo
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoSigningMethod = errors.New("JWT: no JWT signing method") ErrNoHMACKey = errors.New("JWT: you must provide a HMAC Key") ErrNoRSAKey = errors.New("JWT: you must provide a RSA Key") ErrNoECKey = errors.New("JWT: you must provide a EC Key") ErrInvalidSigningMethod = errors.New("JWT: invalid JWT signing method") ErrInvalidDuration = errors.New("JWT: duration of jwt can not be less than or equal to zero") ErrTokenNotFound = errors.New("JWT: there is no token in the given header") ErrNoHeader = errors.New("JWT: there is no specified header which contains a token") )
Functions ¶
func SetSigningMethod ¶
func SetSigningMethod(method string) Jwt.SigningMethod
Types ¶
type JWTClaims ¶
type JWTClaims struct { Jwt.StandardClaims Data map[string]interface{} `json:"data,omitempty"` }
type Store ¶
type Store interface { // Check should check whether a token has been revoked. // If not, it will return some information of user and nil. Check(tokenId string, issuedAt int64) (info *UserInfo, err error) // Revoke should revoke a token which is no longer in use. // This case often happens when a user logs out // or an authorization ends. Revoke(tokenId string) error }
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
func (*Token) Authenticator ¶
func (t *Token) Authenticator() gin.HandlerFunc
Authenticator checks whether user is authenticated.
func (*Token) GenerateToken ¶
func (*Token) GetTokenData ¶
func (*Token) RevokeToken ¶
Click to show internal directories.
Click to hide internal directories.