Documentation ¶
Index ¶
- 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) 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 ¶
This section is empty.
Functions ¶
func IsAuthElsewhere ¶ added in v0.1.1
func IsExpiredToken ¶ added in v0.1.0
func IsIdentityMissing ¶ added in v0.1.1
func IsInvalidSignAlgorithm ¶ added in v0.1.3
func IsInvalidToken ¶ added in v0.1.0
func IsMissingToken ¶ added in v0.1.0
Types ¶
type Http ¶ added in v0.1.3
type Http struct {
// contains filtered or unexported fields
}
func (*Http) DestroyToken ¶ added in v0.1.3
DestroyToken Destroy a token. By default, the token expired error be ignored.
func (*Http) ExtractIdentity ¶ added in v0.1.3
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 ¶ added in v0.1.3
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 ¶ added in v0.1.3
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 ¶ added in v0.1.3
Middleware Implemented basic JWT permission authentication.
func (*Http) RefreshToken ¶ added in v0.1.3
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 ¶ added in v0.1.1
DestroyIdentity Destroy the identification mark.
func (*JWT) DestroyToken ¶ added in v0.1.1
DestroyToken Destroy a token.
func (*JWT) ExtractIdentity ¶ added in v0.1.3
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 ¶ added in v0.1.3
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) IdentityKey ¶ added in v0.1.3
IdentityKey Retrieve identity key.
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 ¶ added in v0.1.3
type Option func(o *options)
func WithIdentityKey ¶ added in v0.1.3
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 WithIssuer ¶ added in v0.1.3
WithIssuer Set the issuer of the token.
func WithLookupLocations ¶ added in v0.1.3
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 ¶ added in v0.1.3
WithPublicPrivateKey Set public key and private key. The signature algorithm is one of RS256, RS384, RS512, ES256, ES384 and ES512
func WithRefreshDuration ¶ added in v0.1.3
WithRefreshDuration Set token refresh duration.
func WithSecretKey ¶ added in v0.1.3
WithSecretKey Set secret key. The signature algorithm is one of HS256, HS384 and HS512
func WithSignAlgorithm ¶ added in v0.1.3
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 ¶ added in v0.1.3
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 ¶ added in v0.1.3
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 ¶ added in v0.1.4
func (s SignAlgorithm) String() string