-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add sign in with facebook * feat: add facebook provider to factory function * feat: add facebook config defaults * feat: use newest facebook api version * feat: make facebook provider consistent with other providers * feat: add check for email We cannot assume a user always has a valid email. Even though it is not the used "me" endpoint, see: https://developers.facebook.com/docs/graph-api/reference/user/ * docs: elaborate comment * fix: fix third party tests * feat: add facebook icon * feat: add appsecret_proof to requests w. access token * refactor: build userinfo url programmatically * feat: map all available name claims --------- Co-authored-by: Prathamesh <[email protected]>
- Loading branch information
1 parent
5023a53
commit d66b267
Showing
20 changed files
with
387 additions
and
5 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -618,6 +618,123 @@ func (s *thirdPartySuite) TestThirdPartyHandler_Callback_SignIn_Microsoft() { | |
} | ||
} | ||
|
||
func (s *thirdPartySuite) TestThirdPartyHandler_Callback_SignUp_Facebook() { | ||
defer gock.Off() | ||
if testing.Short() { | ||
s.T().Skip("skipping test in short mode.") | ||
} | ||
|
||
gock.New(thirdparty.FacebookOauthTokenEndpoint). | ||
Post("/"). | ||
Reply(200). | ||
JSON(map[string]string{"access_token": "fakeAccessToken"}) | ||
|
||
gock.New(thirdparty.FacebookUserInfoEndpoint). | ||
Get("/me"). | ||
Reply(200). | ||
JSON(&thirdparty.FacebookUser{ | ||
ID: "facebook_abcde", | ||
Email: "[email protected]", | ||
}) | ||
|
||
cfg := s.setUpConfig([]string{"facebook"}, []string{"https://example.com"}) | ||
|
||
state, err := thirdparty.GenerateState(cfg, "facebook", "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("facebook", "facebook_abcde") | ||
s.NotNil(identity) | ||
|
||
logs, lerr := s.Storage.GetAuditLogPersister().List(0, 0, nil, nil, []string{"thirdparty_signup_succeeded"}, user.ID.String(), email.Address, "", "") | ||
s.NoError(lerr) | ||
s.Len(logs, 1) | ||
} | ||
} | ||
|
||
func (s *thirdPartySuite) TestThirdPartyHandler_Callback_SignIn_Facebook() { | ||
defer gock.Off() | ||
if testing.Short() { | ||
s.T().Skip("skipping test in short mode.") | ||
} | ||
|
||
err := s.LoadFixtures("../test/fixtures/thirdparty") | ||
s.NoError(err) | ||
|
||
gock.New(thirdparty.FacebookOauthTokenEndpoint). | ||
Post("/"). | ||
Reply(200). | ||
JSON(map[string]string{"access_token": "fakeAccessToken"}) | ||
|
||
gock.New(thirdparty.FacebookUserInfoEndpoint). | ||
Get("/me"). | ||
Reply(200). | ||
JSON(&thirdparty.FacebookUser{ | ||
ID: "facebook_abcde", | ||
Email: "[email protected]", | ||
}) | ||
|
||
cfg := s.setUpConfig([]string{"facebook"}, []string{"https://example.com"}) | ||
|
||
state, err := thirdparty.GenerateState(cfg, "facebook", "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("facebook", "facebook_abcde") | ||
s.NotNil(identity) | ||
|
||
logs, lerr := s.Storage.GetAuditLogPersister().List(0, 0, nil, nil, []string{"thirdparty_signin_succeeded"}, user.ID.String(), "", "", "") | ||
s.NoError(lerr) | ||
s.Len(logs, 1) | ||
} | ||
} | ||
|
||
func (s *thirdPartySuite) TestThirdPartyHandler_Callback_SignUp_WithUnclaimedEmail() { | ||
defer gock.Off() | ||
if testing.Short() { | ||
|
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
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 |
---|---|---|
|
@@ -36,6 +36,12 @@ | |
verified: false | ||
created_at: 2020-12-31 23:59:59 | ||
updated_at: 2020-12-31 23:59:59 | ||
- id: 967ce4a0-677d-4dc3-bacf-53d54471369c | ||
user_id: | ||
address: [email protected] | ||
verified: true | ||
created_at: 2020-12-31 23:59:59 | ||
updated_at: 2020-12-31 23:59:59 | ||
- id: 527afce8-3b7b-41b6-b1ed-33d408c5a7bb | ||
user_id: 43fb7e88-4d5d-4b2b-9335-391e78d7e472 | ||
address: [email protected] | ||
|
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 |
---|---|---|
|
@@ -33,3 +33,10 @@ | |
email_id: d781006b-4f55-4327-bad6-55bc34b88585 | ||
created_at: 2020-12-31 23:59:59 | ||
updated_at: 2020-12-31 23:59:59 | ||
- id: b6b1309d-61de-4a82-b8b8-d54db0be679b | ||
provider_id: "facebook_abcde" | ||
provider_name: "facebook" | ||
data: '{"email":"[email protected]","sub":"facebook_abcde"}' | ||
email_id: d781006b-4f55-4327-bad6-55bc34b88585 | ||
created_at: 2020-12-31 23:59:59 | ||
updated_at: 2020-12-31 23:59:59 |
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
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
Oops, something went wrong.