Skip to content

Add ID to Claims interface#352

Open
st3fan wants to merge 2 commits into
golang-jwt:mainfrom
st3fan:st3fan/adding-jti-to-claims
Open

Add ID to Claims interface#352
st3fan wants to merge 2 commits into
golang-jwt:mainfrom
st3fan:st3fan/adding-jti-to-claims

Conversation

@st3fan

@st3fan st3fan commented Oct 9, 2023

Copy link
Copy Markdown

This patch adds the jti claim to the Claims interface with a GetID() method. It also implements GetID() for both MapClaims and RegisteredClaims.

This makes it easier to use the registered claims (as documented in https://datatracker.ietf.org/doc/html/rfc7519#section-4.1) when you don't know whether you have an instance of RegisteredClaims or MapClaims to work with.

(I have a a concrete use for this where it saves me a type switch to find out what type of claims I am working with)

I realize that this is a drive-by pull request - if this change is unwanted then please discard it.

@oxisto

oxisto commented Oct 9, 2023

Copy link
Copy Markdown
Collaborator

This looks like a good idea, unfortunately this is API breaking, so this is something we need to keep reserved for a future v6, so this might be "stuck" for a while.

@oxisto oxisto added the next The next iteration of development, currently `v6` label Oct 9, 2023
@oxisto oxisto linked an issue Oct 9, 2023 that may be closed by this pull request
@oxisto oxisto added next The next iteration of development, currently `v6` and removed next The next iteration of development, currently `v6` labels Jul 23, 2024
@oxisto oxisto requested review from mfridman and oxisto January 28, 2026 20:01
Comment thread claims.go
GetIssuer() (string, error)
GetSubject() (string, error)
GetAudience() (ClaimStrings, error)
GetID() (string, error)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in the spec this is called JWT ID, we tried to take the "name" of the claim of the spec and use that for the name of the function, so in that case it would be GetJWTID() although I am not really sure if this is a good name. Canonical Go would probably be GetJwtId()?

@oxisto

oxisto commented Jan 28, 2026

Copy link
Copy Markdown
Collaborator

Let's do this, should be one of the first things that will land in v6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next The next iteration of development, currently `v6`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetID in the Claims interface ?

2 participants