Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ID to Claims interface #352

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ 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)
GetNotBefore() (*NumericDate, error)
GetIssuer() (string, error)
GetSubject() (string, error)
GetAudience() (ClaimStrings, error)
GetID() (string, error)
}
5 changes: 5 additions & 0 deletions map_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions registered_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}