Example #1
0
// 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
}
Example #2
0
// 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),
	}
}
Example #3
0
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
}
Example #4
0
// 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()
}
Example #5
0
// 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()
}
Example #6
0
// 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()
}
Example #7
0
// MarshalJSON implements json.Marshaler for Claims.
func (c Claims) MarshalJSON() ([]byte, error) {
	return jwt.Claims(c).MarshalJSON()
}
Example #8
0
// Del removes the value that corresponds with key from the Claims.
func (c Claims) Del(key string) {
	jwt.Claims(c).Del(key)
}
Example #9
0
// 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)
}
Example #10
0
// RemoveNotBefore deletes claim "nbf" from c.
func (c Claims) RemoveNotBefore() {
	jwt.Claims(c).NotBefore()
}
Example #11
0
// RemoveExpiration deletes claim "exp" from c.
func (c Claims) RemoveExpiration() {
	jwt.Claims(c).RemoveExpiration()
}
Example #12
0
// RemoveAudience deletes claim "aud" from c.
func (c Claims) RemoveAudience() {
	jwt.Claims(c).Audience()
}
Example #13
0
// RemoveSubject deletes claim "sub" from c.
func (c Claims) RemoveSubject() {
	jwt.Claims(c).RemoveIssuer()
}
Example #14
0
// 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()
}
Example #15
0
// 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()
}
Example #16
0
// 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)
}
Example #17
0
// 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)
}
Example #18
0
// RemoveIssuedAt deletes claim "iat" from c.
func (c Claims) RemoveIssuedAt() {
	jwt.Claims(c).IssuedAt()
}
Example #19
0
// Set sets Claims[key] = val. It'll overwrite without warning.
func (c Claims) Set(key string, val interface{}) {
	jwt.Claims(c).Set(key, val)
}
Example #20
0
// Get retrieves the value corresponding with key from the Claims.
func (c Claims) Get(key string) interface{} {
	return jwt.Claims(c).Get(key)
}
Example #21
0
// 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)
}
Example #22
0
// RemoveJWTID deletes claim "jti" from c.
func (c Claims) RemoveJWTID() {
	jwt.Claims(c).RemoveJWTID()
}
Example #23
0
// Base64 implements the Encoder interface.
func (c Claims) Base64() ([]byte, error) {
	return jwt.Claims(c).Base64()
}
Example #24
0
// 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)
}
Example #25
0
// 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()
}
Example #26
0
// 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)
}
Example #27
0
// 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()
}
Example #28
0
// 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...)
}
Example #29
0
// 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()
}
Example #30
0
// 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)
}