Documentation
¶
Index ¶
- Variables
- func IsAuthElsewhere(err error) bool
- func IsExpiredToken(err error) bool
- func IsIdentityMissing(err error) bool
- func IsInvalidSignAlgorithm(err error) bool
- func IsInvalidToken(err error) bool
- func IsMissingToken(err error) bool
- type Http
- func (h *Http) DestroyToken(r *http.Request) error
- func (h *Http) ExtractIdentity(r *http.Request, ignoreExpired ...bool) (interface{}, error)
- func (h *Http) ExtractPayload(r *http.Request, ignoreExpired ...bool) (payload Payload, err error)
- func (h *Http) ExtractToken(r *http.Request, ignoreExpired ...bool) (*Token, error)
- func (h *Http) Middleware(r *http.Request) (*http.Request, error)
- func (h *Http) RefreshToken(r *http.Request, ignoreExpired ...bool) (*Token, error)
- type JWT
- func (j *JWT) DestroyIdentity(identity interface{}) error
- func (j *JWT) DestroyToken(token string, ignoreExpired ...bool) error
- func (j *JWT) ExtractIdentity(token string, ignoreExpired ...bool) (interface{}, error)
- func (j *JWT) ExtractPayload(token string, ignoreExpired ...bool) (Payload, error)
- func (j *JWT) GenerateToken(payload Payload) (*Token, error)
- func (j *JWT) Http() *Http
- func (j *JWT) IdentityKey() string
- func (j *JWT) RefreshToken(token string, ignoreExpired ...bool) (*Token, error)
- type Option
- func WithIdentityKey(identityKey string) Option
- func WithIssuer(issuer string) Option
- func WithLookupLocations(locations string) Option
- func WithPublicPrivateKey(publicKey, privateKey string) Option
- func WithRefreshDuration(duration int) Option
- func WithSecretKey(secretKey string) Option
- func WithSignAlgorithm(signAlgorithm SignAlgorithm) Option
- func WithStore(store Store) Option
- func WithValidDuration(duration int) Option
- type Payload
- type SignAlgorithm
- type Store
- type Token
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingToken indicates JWT token is missing ErrMissingToken = errors.New("token is missing") // ErrExpiredToken indicates JWT token has expired. Can't refresh. ErrExpiredToken = errors.New("token is expired") // ErrInvalidToken indicates auth header is invalid, could for example have the wrong issuer ErrInvalidToken = errors.New("token is invalid") // ErrMissingIdentity indicates that there is no corresponding identity information in the payload ErrMissingIdentity = errors.New("identity is missing") // ErrAuthElsewhere indicates that the same identity is logged in elsewhere ErrAuthElsewhere = errors.New("auth elsewhere") // ErrSignAlgorithmNotMatch indicates that the signing method of the token is inconsistent with the configured signing method ErrSignAlgorithmNotMatch = errors.New("sign algorithm does not match") // ErrInvalidSignAlgorithm indicates that the sign algorithm is invalid, must be one of HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384 and ES512 ErrInvalidSignAlgorithm = errors.New("invalid sign algorithm") // ErrInvalidSecretKey indicates that the given secret cacheKey is invalid ErrInvalidSecretKey = errors.New("invalid secret cacheKey") // ErrInvalidPrivateKey indicates that the given private cacheKey is invalid ErrInvalidPrivateKey = errors.New("invalid private cacheKey") // ErrInvalidPublicKey indicates the given public cacheKey is invalid ErrInvalidPublicKey = errors.New("invalid public cacheKey") )
Functions ¶
func IsAuthElsewhere ¶
func IsExpiredToken ¶
func IsIdentityMissing ¶
func IsInvalidSignAlgorithm ¶
func IsInvalidToken ¶
func IsMissingToken ¶
Types ¶
type Http ¶
type Http struct {
// contains filtered or unexported fields
}
func (*Http) DestroyToken ¶
DestroyToken Destroy a token. By default, the token expired error be ignored.
func (*Http) ExtractIdentity ¶
ExtractIdentity Retrieve identity from request. By default, the token expired error doesn't be ignored. You can ignore expired error by setting the `ignoreExpired` parameter.
func (*Http) ExtractPayload ¶
ExtractPayload Retrieve payload from request. By default, the token expired error doesn't be ignored. You can ignore expired error by setting the `ignoreExpired` parameter.
func (*Http) ExtractToken ¶
ExtractToken Extracts and returns a token object from request. By default, the token expired error doesn't be ignored. You can ignore expired error by setting the `ignoreExpired` parameter.
func (*Http) Middleware ¶
Middleware Implemented basic JWT permission authentication.
func (*Http) RefreshToken ¶
RefreshToken Generates and returns a new token object from request. By default, the token expired error doesn't be ignored. You can ignore expired error by setting the `ignoreExpired` parameter.
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
func (*JWT) DestroyIdentity ¶
DestroyIdentity Destroy the identification mark.
func (*JWT) DestroyToken ¶
DestroyToken Destroy a token.
func (*JWT) ExtractIdentity ¶
ExtractIdentity Retrieve identity from token. By default, the token expired error doesn't be ignored. You can ignore expired error by setting the `ignoreExpired` parameter.
func (*JWT) ExtractPayload ¶
ExtractPayload Extracts and returns payload from the token. By default, The token expiration errors will not be ignored. The payload is nil when the token expiration errors not be ignored.
func (*JWT) GenerateToken ¶
GenerateToken Generates and returns a new token object with payload.
func (*JWT) RefreshToken ¶
RefreshToken Retreads and returns a new token object depend on old token. By default, the token expired error doesn't be ignored. You can ignore expired error by setting the `ignoreExpired` parameter.
type Option ¶
type Option func(o *options)
func WithIdentityKey ¶
WithIdentityKey Set the identity key of the token. After opening the identification identifier and cache interface, the system will construct a unique authorization identifier for each token. If the same user is authorized to log in elsewhere, the previous token will no longer be valid.
func WithLookupLocations ¶
WithLookupLocations Set the token lookup locations within requests. Support header, form, cookie and query parameter. Support to seek multiple locations, Separate multiple seek locations with commas.
func WithPublicPrivateKey ¶
WithPublicPrivateKey Set public key and private key. The signature algorithm is one of RS256, RS384, RS512, ES256, ES384 and ES512
func WithRefreshDuration ¶
WithRefreshDuration Set token refresh duration.
func WithSecretKey ¶
WithSecretKey Set secret key. The signature algorithm is one of HS256, HS384 and HS512
func WithSignAlgorithm ¶
func WithSignAlgorithm(signAlgorithm SignAlgorithm) Option
WithSignAlgorithm Set signature algorithm. The secret key must be set when the signature algorithm is one of HS256, HS384 and HS512 The public key and private key must be set when the signature algorithm is one of RS256, RS384 and RS512 The public key and private key must be set when the signature algorithm is one of ES256, ES384 and ES512
func WithValidDuration ¶
WithValidDuration Set token valid duration. If only set the valid duration, The refresh duration will automatically be set to half of the valid duration.
type SignAlgorithm ¶
type SignAlgorithm string
const ( HS256 SignAlgorithm = "HS256" HS512 SignAlgorithm = "HS512" HS384 SignAlgorithm = "HS384" RS256 SignAlgorithm = "RS256" RS384 SignAlgorithm = "RS384" RS512 SignAlgorithm = "RS512" ES256 SignAlgorithm = "ES256" ES384 SignAlgorithm = "ES384" ES512 SignAlgorithm = "ES512" )
func (SignAlgorithm) String ¶
func (s SignAlgorithm) String() string