Documentation ¶
Index ¶
- Variables
- func Authenticator(t *Token) func(next http.Handler) http.Handler
- type Claims
- type Options
- type Store
- type Token
- func (t *Token) CheckToken(tokenString string) (map[string]interface{}, error)
- func (t *Token) GenerateToken(data map[string]interface{}) (string, error)
- func (t *Token) GetToken(req *http.Request) (string, error)
- func (t *Token) RefreshToken(tokenString string) (string, error)
- func (t *Token) RevokeToken(id string) error
- func (t *Token) ValidateToken(tokenString string) (*TokenInfo, error)
- type TokenInfo
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidSigningMethod = errors.New("JWT: invalid signing method") ErrNoHMACKey = errors.New("JWT: no a HMAC key") ErrNoRSAKey = errors.New("JWT: no a RSA key") ErrNoECKey = errors.New("JWT: no a EC key") ErrInvalidToken = errors.New("JWT: invalid token") ErrGetTokenId = errors.New("JWT: can not get id from token") ErrGetIssuedTime = errors.New("JWT: can not get issued time from token") ErrGetData = errors.New("JWT: can not get data from token") ErrNoStore = errors.New("JWT: no store provided") ErrUnexpectedSigningMethod = errors.New("JWT: unexpected signing method") ErrTokenMalformed = errors.New("JWT: token is malformed") ErrTokenNotActive = errors.New("JWT: token is not valid yet") ErrTokenExpired = errors.New("JWT: token is expired") )
Functions ¶
Types ¶
type Claims ¶
type Claims struct { // Standard claims are the standard jwt claims from the ietf standard // https://tools.ietf.org/html/rfc7519 *jwtGo.StandardClaims Data map[string]interface{} `json:"data,omitempty"` }
Claims holds the claims encoded in a JWT
type Options ¶
type Options struct { PrivateKeyLocation string PublicKeyLocation string HMACKey []byte SigningMethod string TTL time.Duration IsBearerToken bool Header string UserProperty string }
Options is a struct for specifying configuration options
type Store ¶
type Store interface { // Check checks whether a token has been revoked // If not, it will return some user data and nil. Check(tokenId string, issuedAt float64) (data map[string]interface{}, err error) // Revoke revokes 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) CheckToken ¶
func (*Token) GenerateToken ¶
GenerateToken generate a JWT. Please don't add sensitive data such as password to payload of JWT.
func (*Token) RefreshToken ¶
RefreshToken regenerate the token after check the given token string is valid.
func (*Token) RevokeToken ¶
RevokeToken revokes a token which is no longer in use. This case often happens when a user logs out. or an authorization ends.
Click to show internal directories.
Click to hide internal directories.