Skip to content

What is the purpose of Claims interface? #347

Answered by oxisto
koote asked this question in Q&A
Discussion options

You must be logged in to vote

Ok a couple of points

I am confused since those new added getters are just return corresponding fields introduced by RegisteredClaims, my custom token even doesn't want claims like iss, sub, aud, etc., Why do we need to be forced to implement those getters? Is it just to strictly follow the RFC standard?

Yes, it is primarily to follow the RFC standard. All fields which are optional in the RFC are optional though and can either be set to nil, e.g, for date-fields or an empty string or an empty array. Since you already embedding jwt.RegisteredClaims in your new example, you don't need to implement the interface. Go will check embedded structs, whether they implement the necessary function…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by koote
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants