mirror of https://github.com/golang-jwt/jwt.git
Add ID to Claims interface
This commit is contained in:
parent
0cb4fa15e3
commit
41af31a765
|
@ -5,7 +5,7 @@ package jwt
|
||||||
// common basis for validation, it is required that an implementation is able to
|
// common basis for validation, it is required that an implementation is able to
|
||||||
// supply at least the claim names provided in
|
// supply at least the claim names provided in
|
||||||
// https://datatracker.ietf.org/doc/html/rfc7519#section-4.1 namely `exp`,
|
// https://datatracker.ietf.org/doc/html/rfc7519#section-4.1 namely `exp`,
|
||||||
// `iat`, `nbf`, `iss`, `sub` and `aud`.
|
// `iat`, `nbf`, `iss`, `sub`, `aud` and `jti“.
|
||||||
type Claims interface {
|
type Claims interface {
|
||||||
GetExpirationTime() (*NumericDate, error)
|
GetExpirationTime() (*NumericDate, error)
|
||||||
GetIssuedAt() (*NumericDate, error)
|
GetIssuedAt() (*NumericDate, error)
|
||||||
|
@ -13,4 +13,5 @@ type Claims interface {
|
||||||
GetIssuer() (string, error)
|
GetIssuer() (string, error)
|
||||||
GetSubject() (string, error)
|
GetSubject() (string, error)
|
||||||
GetAudience() (ClaimStrings, error)
|
GetAudience() (ClaimStrings, error)
|
||||||
|
GetID() (string, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,11 @@ func (m MapClaims) GetSubject() (string, error) {
|
||||||
return m.parseString("sub")
|
return m.parseString("sub")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetID implements the Claims interface.
|
||||||
|
func (m MapClaims) GetID() (string, error) {
|
||||||
|
return m.parseString("jti")
|
||||||
|
}
|
||||||
|
|
||||||
// parseNumericDate tries to parse a key in the map claims type as a number
|
// parseNumericDate tries to parse a key in the map claims type as a number
|
||||||
// date. This will succeed, if the underlying type is either a [float64] or a
|
// date. This will succeed, if the underlying type is either a [float64] or a
|
||||||
// [json.Number]. Otherwise, nil will be returned.
|
// [json.Number]. Otherwise, nil will be returned.
|
||||||
|
|
|
@ -61,3 +61,8 @@ func (c RegisteredClaims) GetIssuer() (string, error) {
|
||||||
func (c RegisteredClaims) GetSubject() (string, error) {
|
func (c RegisteredClaims) GetSubject() (string, error) {
|
||||||
return c.Subject, nil
|
return c.Subject, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetID implements the Claims interface.
|
||||||
|
func (c RegisteredClaims) GetID() (string, error) {
|
||||||
|
return c.ID, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue