-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse email_verified claim correctly from Apple ID token (#2054)
* fix: parse email_verified claim correctly The email_verified claim in the apple identity token can either be a string or a bool. Before it was assumed that it is always a string, but when the claim is of type bool an error is returned. Now the claim type is checked and parsed accordingly. Also when the type check or parsing fails it is assumed that the email is not verified. * test: add test for boolean claim * chore: only log warning when error is not nil
- Loading branch information
1 parent
c9684d1
commit c4f4249
Showing
3 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,7 +275,7 @@ func (s *thirdPartySuite) TestThirdPartyHandler_Callback_SignUp_Apple() { | |
s.T().Skip("skipping test in short mode.") | ||
} | ||
|
||
fakeIdToken := s.setUpAppleIdToken("apple_abcde", "fakeClientID", "[email protected]", true) | ||
fakeIdToken := s.setUpAppleIdToken("apple_abcde", "fakeClientID", "[email protected]", true, false) | ||
gock.New(thirdparty.AppleTokenEndpoint). | ||
Post("/"). | ||
Reply(200). | ||
|
@@ -334,7 +334,66 @@ func (s *thirdPartySuite) TestThirdPartyHandler_Callback_SignIn_Apple() { | |
err := s.LoadFixtures("../test/fixtures/thirdparty") | ||
s.NoError(err) | ||
|
||
fakeIdToken := s.setUpAppleIdToken("apple_abcde", "fakeClientID", "[email protected]", true) | ||
fakeIdToken := s.setUpAppleIdToken("apple_abcde", "fakeClientID", "[email protected]", true, false) | ||
gock.New(thirdparty.AppleTokenEndpoint). | ||
Post("/"). | ||
Reply(200). | ||
JSON(map[string]string{"access_token": "fakeAccessToken", "id_token": fakeIdToken}) | ||
|
||
fakeJwkSet := s.setUpFakeJwkSet() | ||
gock.New(thirdparty.AppleKeysEndpoint). | ||
Get("/"). | ||
Reply(200). | ||
JSON(fakeJwkSet) | ||
|
||
cfg := s.setUpConfig([]string{"apple"}, []string{"https://example.com"}) | ||
|
||
state, err := thirdparty.GenerateState(cfg, "apple", "https://example.com") | ||
s.NoError(err) | ||
|
||
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/thirdparty/callback?code=abcde&state=%s", state), nil) | ||
req.AddCookie(&http.Cookie{ | ||
Name: utils.HankoThirdpartyStateCookie, | ||
Value: string(state), | ||
}) | ||
|
||
c, rec := s.setUpContext(req) | ||
handler := s.setUpHandler(cfg) | ||
|
||
if s.NoError(handler.Callback(c)) { | ||
s.Equal(http.StatusTemporaryRedirect, rec.Code) | ||
|
||
s.assertLocationHeaderHasToken(rec) | ||
s.assertStateCookieRemoved(rec) | ||
|
||
email, err := s.Storage.GetEmailPersister().FindByAddress("[email protected]") | ||
s.NoError(err) | ||
s.NotNil(email) | ||
s.True(email.IsPrimary()) | ||
|
||
user, err := s.Storage.GetUserPersister().Get(*email.UserID) | ||
s.NoError(err) | ||
s.NotNil(user) | ||
|
||
identity := email.Identities.GetIdentity("apple", "apple_abcde") | ||
s.NotNil(identity) | ||
|
||
logs, lerr := s.Storage.GetAuditLogPersister().List(0, 0, nil, nil, []string{"thirdparty_signin_succeeded"}, user.ID.String(), email.Address, "", "") | ||
s.NoError(lerr) | ||
s.Len(logs, 1) | ||
} | ||
} | ||
|
||
func (s *thirdPartySuite) TestThirdPartyHandler_Callback_SignIn_Apple_WithBooleanEmailVerifiedClaim() { | ||
defer gock.Off() | ||
if testing.Short() { | ||
s.T().Skip("skipping test in short mode.") | ||
} | ||
|
||
err := s.LoadFixtures("../test/fixtures/thirdparty") | ||
s.NoError(err) | ||
|
||
fakeIdToken := s.setUpAppleIdToken("apple_abcde", "fakeClientID", "[email protected]", true, true) | ||
gock.New(thirdparty.AppleTokenEndpoint). | ||
Post("/"). | ||
Reply(200). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters