// Claims helps implements jwt.JWT. func (j *jws) Claims() jwt.Claims { if j.isJWT { if c, ok := j.payload.v.(Claims); ok { return jwt.Claims(c) } } return nil }
// NewValidator returns a pointer to a jwt.Validator structure containing // the info to be used in the validation of a JWT. func NewValidator(c Claims, exp, nbf float64, fn func(Claims) error) *jwt.Validator { return &jwt.Validator{ Expected: jwt.Claims(c), EXP: exp, NBF: nbf, Fn: Conv(fn), } }
func (j *jws) Validate(key interface{}, m crypto.SigningMethod, v ...*jwt.Validator) error { if j.isJWT { if err := j.Verify(key, m); err != nil { return err } var v1 jwt.Validator if len(v) > 0 { v1 = *v[0] } c, ok := j.payload.v.(Claims) if ok { if err := v1.Validate(j); err != nil { return err } return jwt.Claims(c).Validate(float64(time.Now().Unix()), v1.EXP, v1.NBF) } } return ErrIsNotJWT }
// NotBefore retrieves claim "nbf" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.5 func (c Claims) NotBefore() (time.Time, bool) { return jwt.Claims(c).NotBefore() }
// Audience retrieves claim "aud" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.3 func (c Claims) Audience() ([]string, bool) { return jwt.Claims(c).Audience() }
// Issuer retrieves claim "iss" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.1 func (c Claims) Issuer() (string, bool) { return jwt.Claims(c).Issuer() }
// MarshalJSON implements json.Marshaler for Claims. func (c Claims) MarshalJSON() ([]byte, error) { return jwt.Claims(c).MarshalJSON() }
// Del removes the value that corresponds with key from the Claims. func (c Claims) Del(key string) { jwt.Claims(c).Del(key) }
// SetJWTID sets claim "jti" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.7 func (c Claims) SetJWTID(uniqueID string) { jwt.Claims(c).SetJWTID(uniqueID) }
// RemoveNotBefore deletes claim "nbf" from c. func (c Claims) RemoveNotBefore() { jwt.Claims(c).NotBefore() }
// RemoveExpiration deletes claim "exp" from c. func (c Claims) RemoveExpiration() { jwt.Claims(c).RemoveExpiration() }
// RemoveAudience deletes claim "aud" from c. func (c Claims) RemoveAudience() { jwt.Claims(c).Audience() }
// RemoveSubject deletes claim "sub" from c. func (c Claims) RemoveSubject() { jwt.Claims(c).RemoveIssuer() }
// JWTID retrieves claim "jti" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.7 func (c Claims) JWTID() (string, bool) { return jwt.Claims(c).JWTID() }
// IssuedAt retrieves claim "iat" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.6 func (c Claims) IssuedAt() (float64, bool) { return jwt.Claims(c).IssuedAt() }
// SetNotBefore sets claim "nbf" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.5 func (c Claims) SetNotBefore(notBefore time.Time) { jwt.Claims(c).SetNotBefore(notBefore) }
// SetIssuedAt sets claim "iat" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.6 func (c Claims) SetIssuedAt(issuedAt time.Time) { jwt.Claims(c).SetIssuedAt(issuedAt) }
// RemoveIssuedAt deletes claim "iat" from c. func (c Claims) RemoveIssuedAt() { jwt.Claims(c).IssuedAt() }
// Set sets Claims[key] = val. It'll overwrite without warning. func (c Claims) Set(key string, val interface{}) { jwt.Claims(c).Set(key, val) }
// Get retrieves the value corresponding with key from the Claims. func (c Claims) Get(key string) interface{} { return jwt.Claims(c).Get(key) }
// Has returns true if a value for the given key exists inside the Claims. func (c Claims) Has(key string) bool { return jwt.Claims(c).Has(key) }
// RemoveJWTID deletes claim "jti" from c. func (c Claims) RemoveJWTID() { jwt.Claims(c).RemoveJWTID() }
// Base64 implements the Encoder interface. func (c Claims) Base64() ([]byte, error) { return jwt.Claims(c).Base64() }
// SetIssuer sets claim "iss" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.1 func (c Claims) SetIssuer(issuer string) { jwt.Claims(c).SetIssuer(issuer) }
// Subject retrieves claim "sub" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.2 func (c Claims) Subject() (string, bool) { return jwt.Claims(c).Subject() }
// SetSubject sets claim "iss" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.2 func (c Claims) SetSubject(subject string) { jwt.Claims(c).SetSubject(subject) }
// Expiration retrieves claim "exp" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.4 func (c Claims) Expiration() (time.Time, bool) { return jwt.Claims(c).Expiration() }
// SetAudience sets claim "aud" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.3 func (c Claims) SetAudience(audience ...string) { jwt.Claims(c).SetAudience(audience...) }
// IssuedAt retrieves claim "iat" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.6 func (c Claims) IssuedAt() (time.Time, bool) { return jwt.Claims(c).IssuedAt() }
// SetExpiration sets claim "exp" per its type in // https://tools.ietf.org/html/rfc7519#section-4.1.4 func (c Claims) SetExpiration(expiration time.Time) { jwt.Claims(c).SetExpiration(expiration) }