-
Notifications
You must be signed in to change notification settings - Fork 396
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
feat: allow minimising the jwt size by omitting additional claims #1920
base: master
Are you sure you want to change the base?
Changes from all commits
2f8edec
e067caa
1126963
3a94975
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ import ( | |
// AccessTokenClaims is a struct thats used for JWT claims | ||
type AccessTokenClaims struct { | ||
jwt.RegisteredClaims | ||
Email string `json:"email"` | ||
Phone string `json:"phone"` | ||
AppMetaData map[string]interface{} `json:"app_metadata"` | ||
Email string `json:"email,omitempty"` | ||
Phone string `json:"phone,omitempty"` | ||
AppMetaData map[string]interface{} `json:"app_metadata,omitempty"` | ||
UserMetaData map[string]interface{} `json:"user_metadata"` | ||
Role string `json:"role"` | ||
AuthenticatorAssuranceLevel string `json:"aal,omitempty"` | ||
|
@@ -333,15 +333,26 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user | |
ExpiresAt: jwt.NewNumericDate(expiresAt), | ||
Issuer: config.JWT.Issuer, | ||
}, | ||
Email: user.GetEmail(), | ||
Phone: user.GetPhone(), | ||
AppMetaData: user.AppMetaData, | ||
UserMetaData: user.UserMetaData, | ||
Role: user.Role, | ||
SessionId: sid, | ||
AuthenticatorAssuranceLevel: aal.String(), | ||
AuthenticationMethodReference: amr, | ||
IsAnonymous: user.IsAnonymous, | ||
AuthenticatorAssuranceLevel: aal.String(), | ||
SessionId: sid, | ||
Role: user.Role, | ||
IsAnonymous: user.IsAnonymous, | ||
Comment on lines
+336
to
+339
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's alright for
I didn't test this but i'm guessing it's required because if those claims are omitted, they may break existing functionality if either (1) or (2) are enabled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, I initially made them optional but decided to wait for the decision out of #1913 if we should have them. Some tests also started breaking with these omitted: https://github.com/supabase/auth/actions/runs/12866198657/job/35868267108#step:11:1147, which further motivated me to keep them as it seem a good indicator that they might be required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought about this a bit more and i think it's safe to let the user decide whether |
||
} | ||
|
||
// add additional claims that are optional | ||
for _, ac := range config.JWT.AdditionalClaims { | ||
switch ac { | ||
case "email": | ||
claims.Email = user.GetEmail() | ||
case "phone": | ||
claims.Phone = user.GetPhone() | ||
case "app_metadata": | ||
claims.AppMetaData = user.AppMetaData | ||
case "user_metadata": | ||
claims.UserMetaData = user.UserMetaData | ||
case "amr": | ||
claims.AuthenticationMethodReference = amr | ||
} | ||
} | ||
|
||
var gotrueClaims jwt.Claims = claims | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noticed this while testing by excluding
user_metadata
inGOTRUE_JWT_ADDITIONAL_CLAIMS
and got the following payload in the JWT returned:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!