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

fix: support string "true" in SSO for Jumpcloud email_verified field #12257 #12318

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/auth/types/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Claims struct {
jwt.Claims
Groups []string `json:"groups,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
EmailVerified bool `json:"-"`
Copy link
Member

@agilgur5 agilgur5 May 18, 2024

Choose a reason for hiding this comment

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

Hmm I'm thinking the more correct way of handling this may have been to use a custom type that handles unmarshaling for this scenario like in this SO question's answers

Name string `json:"name,omitempty"`
ServiceAccountName string `json:"service_account_name,omitempty"`
ServiceAccountNamespace string `json:"service_account_namespace,omitempty"`
Expand Down Expand Up @@ -52,6 +52,10 @@ func (c *Claims) UnmarshalJSON(data []byte) error {
return err
}

if localClaim.RawClaim["email_verified"] == true || localClaim.RawClaim["email_verified"] == "true" {
localClaim.EmailVerified = true
}

*c = Claims(localClaim)
return nil
}
Expand Down
22 changes: 22 additions & 0 deletions server/auth/types/claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ func TestUnmarshalJSON(t *testing.T) {
},
},
},
{
description: "email verify field as string",
data: `{"email_verified":"true"}`,
expectedErr: nil,
expectedClaims: &Claims{
RawClaim: map[string]interface{}{
"email_verified": "true",
},
EmailVerified: true,
},
},
{
description: "email verify field as bool",
data: `{"email_verified":true}`,
expectedErr: nil,
expectedClaims: &Claims{
RawClaim: map[string]interface{}{
"email_verified": true,
},
EmailVerified: true,
},
},
{
description: "unmarshal no data",
data: `{}`,
Expand Down