Add ID to Claims interface

This commit is contained in:
Stefan Arentz 2023-10-09 13:38:32 -04:00
parent 0cb4fa15e3
commit 41af31a765
3 changed files with 12 additions and 1 deletions

View File

@ -5,7 +5,7 @@ package jwt
// common basis for validation, it is required that an implementation is able to
// supply at least the claim names provided in
// 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 {
GetExpirationTime() (*NumericDate, error)
GetIssuedAt() (*NumericDate, error)
@ -13,4 +13,5 @@ type Claims interface {
GetIssuer() (string, error)
GetSubject() (string, error)
GetAudience() (ClaimStrings, error)
GetID() (string, error)
}

View File

@ -39,6 +39,11 @@ func (m MapClaims) GetSubject() (string, error) {
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
// date. This will succeed, if the underlying type is either a [float64] or a
// [json.Number]. Otherwise, nil will be returned.

View File

@ -61,3 +61,8 @@ func (c RegisteredClaims) GetIssuer() (string, error) {
func (c RegisteredClaims) GetSubject() (string, error) {
return c.Subject, nil
}
// GetID implements the Claims interface.
func (c RegisteredClaims) GetID() (string, error) {
return c.ID, nil
}