-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow unverified email signins (#1301)
## What kind of change does this PR introduce? * If `GOTRUE_ALLOW_UNVERIFIED_EMAIL_SIGN_INS` is enabled, it will allow a user with an unverified email address to sign in and obtain an access token JWT * This is particularly useful for OAuth in cases where the oauth provider doesn't return an email address / the oauth user didn't verify their email address with the OAuth provider. * Tests that broke and needed fixing were due to these reasons: * `RemoveUnconfirmedIdentities` was previously buggy and shouldn't be retaining the user metadata of a previously unconfirmed identity * `GOTRUE_ALLOW_UNVERIFIED_EMAIL_SIGN_INS` is enabled by default which caused some tests to return an access token instead of an error for a user with an unverified email ## Modifications made to automatic linking algorithm * If the candidate identity doesn't have a verified email, the decision should be to create a new account. * If the email belongs to a user already, then we opt to create a new user with no email. Previously, we would attempt to create a new user and the db will return an error due to the partial unique constraint on email violation. In order to add an email to the new user, they would have to call update user (`PUT /user`) to add a new email.
- Loading branch information
1 parent
69feebc
commit 94293b7
Showing
13 changed files
with
349 additions
and
202 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,7 +196,7 @@ func (ts *ExternalTestSuite) TestSignupExternalAzureDisableSignupSuccessWithPrim | |
|
||
ts.Config.DisableSignup = true | ||
|
||
ts.createUser("azuretestid", "[email protected]", "Azure Test", "http://example.com/avatar", "") | ||
ts.createUser("azuretestid", "[email protected]", "Azure Test", "", "") | ||
|
||
tokenCount := 0 | ||
code := "authcode" | ||
|
@@ -205,14 +205,14 @@ func (ts *ExternalTestSuite) TestSignupExternalAzureDisableSignupSuccessWithPrim | |
|
||
u := performAuthorization(ts, "azure", code, "") | ||
|
||
assertAuthorizationSuccess(ts, u, tokenCount, -1, "[email protected]", "Azure Test", "azuretestid", "http://example.com/avatar") | ||
assertAuthorizationSuccess(ts, u, tokenCount, -1, "[email protected]", "Azure Test", "azuretestid", "") | ||
} | ||
|
||
func (ts *ExternalTestSuite) TestInviteTokenExternalAzureSuccessWhenMatchingToken() { | ||
setupAzureOverrideVerifiers() | ||
|
||
// name should be populated from Azure API | ||
ts.createUser("azuretestid", "[email protected]", "", "http://example.com/avatar", "invite_token") | ||
ts.createUser("azuretestid", "[email protected]", "", "", "invite_token") | ||
|
||
tokenCount := 0 | ||
code := "authcode" | ||
|
@@ -221,7 +221,7 @@ func (ts *ExternalTestSuite) TestInviteTokenExternalAzureSuccessWhenMatchingToke | |
|
||
u := performAuthorization(ts, "azure", code, "invite_token") | ||
|
||
assertAuthorizationSuccess(ts, u, tokenCount, -1, "[email protected]", "Azure Test", "azuretestid", "http://example.com/avatar") | ||
assertAuthorizationSuccess(ts, u, tokenCount, -1, "[email protected]", "Azure Test", "azuretestid", "") | ||
} | ||
|
||
func (ts *ExternalTestSuite) TestInviteTokenExternalAzureErrorWhenNoMatchingToken() { | ||
|
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 |
---|---|---|
|
@@ -267,6 +267,7 @@ func (ts *ExternalTestSuite) TestInviteTokenExternalGitHubErrorWhenEmailDoesntMa | |
} | ||
|
||
func (ts *ExternalTestSuite) TestSignupExternalGitHubErrorWhenVerifiedFalse() { | ||
ts.Config.Mailer.AllowUnverifiedEmailSignIns = false | ||
tokenCount, userCount := 0, 0 | ||
code := "authcode" | ||
emails := `[{"email":"[email protected]", "primary": true, "verified": false}]` | ||
|
@@ -279,7 +280,7 @@ func (ts *ExternalTestSuite) TestSignupExternalGitHubErrorWhenVerifiedFalse() { | |
ts.Require().NoError(err) | ||
ts.Equal("unauthorized_client", v.Get("error")) | ||
ts.Equal("401", v.Get("error_code")) | ||
ts.Equal("Unverified email with github. A confirmation email has been sent to your github email.", v.Get("error_description")) | ||
ts.Equal("Unverified email with github. A confirmation email has been sent to your github email", v.Get("error_description")) | ||
assertAuthorizationFailure(ts, u, "", "", "") | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -197,6 +197,7 @@ func (ts *ExternalTestSuite) TestInviteTokenExternalKakaoErrorWhenEmailDoesntMat | |
} | ||
|
||
func (ts *ExternalTestSuite) TestSignupExternalKakaoErrorWhenVerifiedFalse() { | ||
ts.Config.Mailer.AllowUnverifiedEmailSignIns = false | ||
tokenCount, userCount := 0, 0 | ||
code := "authcode" | ||
emails := `[{"email":"[email protected]", "primary": true, "verified": false}]` | ||
|
@@ -209,7 +210,7 @@ func (ts *ExternalTestSuite) TestSignupExternalKakaoErrorWhenVerifiedFalse() { | |
ts.Require().NoError(err) | ||
ts.Equal("unauthorized_client", v.Get("error")) | ||
ts.Equal("401", v.Get("error_code")) | ||
ts.Equal("Unverified email with kakao. A confirmation email has been sent to your kakao email.", v.Get("error_description")) | ||
ts.Equal("Unverified email with kakao. A confirmation email has been sent to your kakao email", v.Get("error_description")) | ||
assertAuthorizationFailure(ts, u, "", "", "") | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -78,15 +78,15 @@ func (ts *ExternalTestSuite) TestSignupExternalKeycloakWithoutURLSetup() { | |
|
||
func (ts *ExternalTestSuite) TestSignupExternalKeycloak_AuthorizationCode() { | ||
ts.Config.DisableSignup = false | ||
ts.createUser("keycloaktestid", "[email protected]", "Keycloak Test", "http://example.com/avatar", "") | ||
ts.createUser("keycloaktestid", "[email protected]", "Keycloak Test", "", "") | ||
tokenCount, userCount := 0, 0 | ||
code := "authcode" | ||
server := KeycloakTestSignupSetup(ts, &tokenCount, &userCount, code, keycloakUser) | ||
defer server.Close() | ||
|
||
u := performAuthorization(ts, "keycloak", code, "") | ||
|
||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Keycloak Test", "keycloaktestid", "http://example.com/avatar") | ||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Keycloak Test", "keycloaktestid", "") | ||
} | ||
|
||
func (ts *ExternalTestSuite) TestSignupExternalKeycloakDisableSignupErrorWhenNoUser() { | ||
|
@@ -117,7 +117,7 @@ func (ts *ExternalTestSuite) TestSignupExternalKeycloakDisableSignupErrorWhenNoE | |
func (ts *ExternalTestSuite) TestSignupExternalKeycloakDisableSignupSuccessWithPrimaryEmail() { | ||
ts.Config.DisableSignup = true | ||
|
||
ts.createUser("keycloaktestid", "[email protected]", "Keycloak Test", "http://example.com/avatar", "") | ||
ts.createUser("keycloaktestid", "[email protected]", "Keycloak Test", "", "") | ||
|
||
tokenCount, userCount := 0, 0 | ||
code := "authcode" | ||
|
@@ -126,12 +126,12 @@ func (ts *ExternalTestSuite) TestSignupExternalKeycloakDisableSignupSuccessWithP | |
|
||
u := performAuthorization(ts, "keycloak", code, "") | ||
|
||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Keycloak Test", "keycloaktestid", "http://example.com/avatar") | ||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Keycloak Test", "keycloaktestid", "") | ||
} | ||
|
||
func (ts *ExternalTestSuite) TestInviteTokenExternalKeycloakSuccessWhenMatchingToken() { | ||
// name and avatar should be populated from Keycloak API | ||
ts.createUser("keycloaktestid", "[email protected]", "", "http://example.com/avatar", "invite_token") | ||
ts.createUser("keycloaktestid", "[email protected]", "", "", "invite_token") | ||
|
||
tokenCount, userCount := 0, 0 | ||
code := "authcode" | ||
|
@@ -140,7 +140,7 @@ func (ts *ExternalTestSuite) TestInviteTokenExternalKeycloakSuccessWhenMatchingT | |
|
||
u := performAuthorization(ts, "keycloak", code, "invite_token") | ||
|
||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Keycloak Test", "keycloaktestid", "http://example.com/avatar") | ||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Keycloak Test", "keycloaktestid", "") | ||
} | ||
|
||
func (ts *ExternalTestSuite) TestInviteTokenExternalKeycloakErrorWhenNoMatchingToken() { | ||
|
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 |
---|---|---|
|
@@ -107,7 +107,7 @@ func (ts *ExternalTestSuite) TestSignupExternalTwitchDisableSignupErrorWhenEmpty | |
func (ts *ExternalTestSuite) TestSignupExternalTwitchDisableSignupSuccessWithPrimaryEmail() { | ||
ts.Config.DisableSignup = true | ||
|
||
ts.createUser("twitchTestId", "[email protected]", "Twitch Test", "https://s.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8", "") | ||
ts.createUser("twitchTestId", "[email protected]", "Twitch user", "https://s.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8", "") | ||
|
||
tokenCount, userCount := 0, 0 | ||
code := "authcode" | ||
|
@@ -116,7 +116,7 @@ func (ts *ExternalTestSuite) TestSignupExternalTwitchDisableSignupSuccessWithPri | |
|
||
u := performAuthorization(ts, "twitch", code, "") | ||
|
||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Twitch Test", "twitchTestId", "https://s.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8") | ||
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "[email protected]", "Twitch user", "twitchTestId", "https://s.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8") | ||
} | ||
|
||
func (ts *ExternalTestSuite) TestInviteTokenExternalTwitchSuccessWhenMatchingToken() { | ||
|
Oops, something went wrong.