Skip to content

Commit

Permalink
fix: json schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
staaldraad committed Jan 20, 2025
1 parent 1126963 commit 3a94975
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions internal/api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type AccessTokenClaims struct {
AuthenticatorAssuranceLevel string `json:"aal,omitempty"`
AuthenticationMethodReference []models.AMREntry `json:"amr,omitempty"`
SessionId string `json:"session_id,omitempty"`
IsAnonymous bool `json:"is_anonymous,omitempty"`
IsAnonymous bool `json:"is_anonymous"`
}

// AccessTokenResponse represents an OAuth2 success response
Expand Down Expand Up @@ -336,6 +336,7 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user
AuthenticatorAssuranceLevel: aal.String(),
SessionId: sid,
Role: user.Role,
IsAnonymous: user.IsAnonymous,
}

// add additional claims that are optional
Expand All @@ -351,8 +352,6 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user
claims.UserMetaData = user.UserMetaData
case "amr":
claims.AuthenticationMethodReference = amr
case "is_anonymous":
claims.IsAnonymous = user.IsAnonymous
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/api/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (ts *TokenTestSuite) TestConfigureAccessToken() {
additionalClaimsConfig []string
expectedClaims []string
}
requiredClaims := []string{"aud", "exp", "iat", "sub", "role", "aal", "session_id", "user_metadata"}
requiredClaims := []string{"aud", "exp", "iat", "sub", "role", "aal", "session_id", "user_metadata", "is_anonymous"}
cases := []customAccessTokenTestcase{

{
Expand Down
2 changes: 1 addition & 1 deletion internal/conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ func (config *GlobalConfiguration) ApplyDefaults() error {
// also allow setting to default claims using the "default" keyword, making it possible to use
// this config as a binary flag "none" == use_mimimal_jwt == true, "default" == use_mimimal_jwt == false
if len(config.JWT.AdditionalClaims) == 0 || (len(config.JWT.AdditionalClaims) == 1 && config.JWT.AdditionalClaims[0] == "default") {
config.JWT.AdditionalClaims = []string{"email", "phone", "app_metadata", "user_metadata", "amr", "is_anonymous"}
config.JWT.AdditionalClaims = []string{"email", "phone", "app_metadata", "user_metadata", "amr"}
}

if config.JWT.Exp == 0 {
Expand Down
4 changes: 2 additions & 2 deletions internal/hooks/auth_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const MinimumViableTokenSchema = `{
"type": "string"
}
},
"required": ["aud", "exp", "iat", "sub", "email", "phone", "role", "aal", "session_id", "is_anonymous"]
"required": ["aud", "exp", "iat", "sub", "role", "aal", "session_id"]
}`

// AccessTokenClaims is a struct thats used for JWT claims
Expand All @@ -108,7 +108,7 @@ type AccessTokenClaims struct {
AuthenticatorAssuranceLevel string `json:"aal,omitempty"`
AuthenticationMethodReference []models.AMREntry `json:"amr,omitempty"`
SessionId string `json:"session_id,omitempty"`
IsAnonymous bool `json:"is_anonymous,omitempty"`
IsAnonymous bool `json:"is_anonymous"`
}

type MFAVerificationAttemptInput struct {
Expand Down

0 comments on commit 3a94975

Please sign in to comment.