Repository navigation
Refuse an external registration whose e-mail already has an account - #1071
Merged
Merged
Conversation
A Google or Facebook sign-in with an unknown identity registered a new customer with the provider's e-mail without checking it, so a second account with the same e-mail could exist next to the original one. The registration now applies the same rule as the registration form (per store when customers register per store) and shows "The specified email already exists"; the existing customer signs in and connects the provider instead.
added 6 commits
November 19, 2026 17:54
GetCustomerByEmail and GetCustomerByUsername ignore the store unless customers register per store, so callers pass the store as it is instead of repeating the RegisterCustomersPerStore check.
- Refuse a provider e-mail that is another customer's username, and a provider that shares no e-mail - Check the e-mail before the registration type, so the owner learns to sign in and connect - Tell the customer what to do next instead of the registration form's message - Refuse a taken e-mail or username in RegisterCustomer itself, for every registration path - Inline the store id aliases and fix the stale OIDC lookup comment
…tration-email-exists # Conflicts: # src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
…tration-email-exists # Conflicts: # src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
When someone signs in with Google or Facebook and the store does not know that external identity yet,
ExternalAuthenticationService.RegisterNewUserregisters a new customer with the provider's e-mail. It never checked whether a customer with that e-mail already exists.Result: a second account with the same e-mail is created next to the original one. The original account is not taken over, because the external identity is linked to the new account, not the old one. But two accounts share one e-mail:
GetCustomerByEmailreturns one of them, which one depends on the database.The registration form (
RegisterValidator) and the OIDC login in core already refuse an e-mail that is taken; only this path skipped the check.While adding the check, a second problem showed up: every caller of
GetCustomerByEmail/GetCustomerByUsernamerepeatedRegisterCustomersPerStore ? storeId : ""itself. Without per-store identity the service searched only the given store, so a caller that forgot the rule silently missed customers of other stores.Solution
AuthenticateNewUserlooks up the provider's e-mail in the current store, as an e-mail and, with usernames enabled, as a username (registration stores it as both).ExternalAuthStatus.EmailAlreadyExists. The check runs before the registration type, so with registration disabled the owner is still told to sign in and connect, not that registration is closed.ExternalAuthStatus.EmailRequired.ExternalSignInServiceshows two new resources on the external authentication error page:Account.AssociatedExternalAuth.EmailAlreadyExists(sign in, recover the password if you never set one, then connect) andAccount.AssociatedExternalAuth.EmailRequired. Both are inDefaultLanguage.xmlandUpgrade/en_250.xml.CustomerManagerService.RegisterCustomeritself refuses an e-mail, or with usernames enabled a username, that another customer already has. Every registration path still answers this itself with a proper message; the guard stops a path that forgot to (future plugins, API) and narrows the window between two concurrent registrations. It does not close that window completely - only a unique index would, and with guests (empty e-mail) and per-store identity that is a separate change.CustomerService.GetCustomerByEmailandGetCustomerByUsernameown the per-store rule: the store narrows the lookup only withCustomer:RegisterCustomersPerStore; otherwise the lookup is global. Callers pass the store as it is, and the repeated checks are gone (account controller, storefront validators, admin customer validator and service, merchandise return search, OIDC resolver and profile sync, frontend API login).The existing customer signs in with their password and connects Google/Facebook from their account. That path (
AuthenticateNewUserwith a signed-in customer) is unchanged.Breaking changes
ExternalAuthStatushas two new values. Code that switches over it without a default should handleEmailAlreadyExistsandEmailRequired.ICustomerManagerService.RegisterCustomerthrowsGrandExceptionfor an e-mail or username used by another customer. Custom registration code should check first, as the built-in paths do.GetCustomerByEmail/GetCustomerByUsernamewith a store id no longer search only that store; they search all stores, as with an empty store id. Every caller in the repository already passed an empty store id in that mode, so behaviour does not change for them; custom code that relied on the store-only search does.CustomerConfigwas removed from the constructors that only used it for that check:AccountController,TokenWebController,LoginWebValidator,OidcProfileSynchronizer,MerchandiseReturnViewModelService, and the storefront validatorsRegisterValidator,LoginValidator,PasswordRecoveryValidator,PasswordRecoveryConfirmValidator,SubAccountCreateValidator,SubAccountEditValidator,CustomerInfoValidator.Testing
Grand.Business.Customers.Tests: 156 passed. With per-store identity off, a store id no longer narrows the e-mail and username lookups;RegisterCustomerrefuses another customer's e-mail or username and accepts the registering customer's own.Grand.Business.Authentication.Tests: 403 passed. An unknown identity with a taken e-mail or username registers nobody and stores no association, also with registration disabled; one without an e-mail is refused.Grand.Web.Common.Tests759,Grand.Web.Tests619,Grand.Module.Api.Tests110,Grand.Modules.Tests398: all passed.Grand.Web.Admin.Tests2058 andGrand.Web.Store.Tests241 passed before the last commit, which does not touch those projects.GrandNode.slnx) builds.