Documentation ¶
Index ¶
- func Decode(token string) (josejwt.Claims, error)
- func Sign(claims josejwt.Claims, method josecrypto.SigningMethod, key interface{}) (string, error)
- func StrToKeys(keys ...string) (res []interface{})
- func Verify(token josejwt.JWT, method josecrypto.SigningMethod, keys []interface{}, ...) (claims josejwt.Claims, err error)
- type JWT
- func (j *JWT) Decode(token string) (josejwt.Claims, error)
- func (j *JWT) GetExpiresIn() time.Duration
- func (j *JWT) SetAudience(audience ...string)
- func (j *JWT) SetBackupSigning(method josecrypto.SigningMethod, keys ...interface{})
- func (j *JWT) SetExpiresIn(expiresIn time.Duration)
- func (j *JWT) SetIssuer(issuer string)
- func (j *JWT) SetKeys(keys ...interface{})
- func (j *JWT) SetMethods(method josecrypto.SigningMethod)
- func (j *JWT) SetSigning(method josecrypto.SigningMethod, keys ...interface{})
- func (j *JWT) SetValidator(validator *josejwt.Validator)
- func (j *JWT) Sign(content map[string]interface{}, expiresIn ...time.Duration) (string, error)
- func (j *JWT) Verify(token string) (claims josejwt.Claims, err error)
- type KeyPair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sign ¶
func Sign(claims josejwt.Claims, method josecrypto.SigningMethod, key interface{}) (string, error)
Sign creates a JWT token with the given claims, signing method and key.
Types ¶
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT represents a module. it can be use to create, decode or verify JWT token.
func New ¶
func New(keys ...interface{}) *JWT
New returns a JWT instance. if key omit, jwt will use crypto.Unsecured as signing method. Otherwise crypto.SigningMethodHS256 will be used. You can change it by jwt.SetMethods.
func (*JWT) GetExpiresIn ¶
GetExpiresIn returns jwt's expiration.
func (*JWT) SetAudience ¶ added in v1.5.4
SetAudience sets claim "aud" per its type in https://tools.ietf.org/html/rfc7519#section-4.1.3
func (*JWT) SetBackupSigning ¶ added in v1.6.0
func (j *JWT) SetBackupSigning(method josecrypto.SigningMethod, keys ...interface{})
SetBackupSigning add a backup signing for Verify method, not for Sign method.
func (*JWT) SetExpiresIn ¶
SetExpiresIn set a expire duration to jwt. Default to 0, no "exp" will be added.
func (*JWT) SetKeys ¶
func (j *JWT) SetKeys(keys ...interface{})
SetKeys set new keys to jwt. [deprecated] Please use SetSigning method.
func (*JWT) SetMethods ¶
func (j *JWT) SetMethods(method josecrypto.SigningMethod)
SetMethods set one or more signing methods which can be used rotational. [deprecated] Please use SetSigning method.
func (*JWT) SetSigning ¶ added in v1.6.0
func (j *JWT) SetSigning(method josecrypto.SigningMethod, keys ...interface{})
SetSigning add signing method and keys.
func (*JWT) SetValidator ¶
SetValidator set a custom jwt.Validator to jwt. Default to nil.
func (*JWT) Sign ¶
Sign creates a JWT token with the given content and optional expiresIn.
token1, err1 := jwt.Sign(map[string]interface{}{"UserId": "xxxxx"}) // or claims := josejwt.Claims{} // or claims := josejws.Claims{} claims.Set("hello", "world") token2, err2 := jwt.Sign(claims)
if expiresIn <= 0, expiration will not be set to claims:
token1, err1 := jwt.Sign(map[string]interface{}{"UserId": "xxxxx"}, time.Duration(0))