fix(external): only fire after-user-created hook on account creation - #2756
Open
Mpradeep-dev wants to merge 4 commits into
Open
fix(external): only fire after-user-created hook on account creation#2756Mpradeep-dev wants to merge 4 commits into
Mpradeep-dev wants to merge 4 commits into
Conversation
The external OAuth callback discarded the AccountLinkingDecision returned by createAccountFromExternalIdentity and unconditionally set createdUser = true, so the after-user-created hook ran on every sign-in for GitHub, Google and other external providers - including returning users (AccountExists) and identity links (LinkAccount). Gate createdUser on decision == models.CreateAccount, matching the OIDC, Web3 and SAML sign-in paths and the documented "runs after a user is created" contract.
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.
What
The
after-user-createdhook is documented to run once, after a new user iscreated. On the external OAuth callback path it instead runs on every
sign-in.
In
internalExternalProviderCallback(internal/api/external.go), the accountcreation branch throws away the
AccountLinkingDecisionreturned bycreateAccountFromExternalIdentityand hard-codescreatedUser = true:That branch handles every external OAuth sign-in, so the hook also fires for
AccountExists(a returning user) andLinkAccount(a new identity linked toan existing user). The equivalent call sites in
token_oidc.go,web3.goandsamlacs.goall gate the hook ondecision == models.CreateAccount.Fix
Capture the decision and gate
createdUseron it, matching the other threesign-in paths:
Testing
New regression test
TestExternal/TestExternalCallbackAfterUserCreatedHookOnlyOnSignupin
internal/api/external_test.go:after-user-createdHTTP hook and runs the GitHub OAuthcallback twice for the same identity;
returning-user sign-in.
It fails before this change (hook fires twice) and passes after. Verified
locally with
-race:go test ./internal/api/ -run TestExternal -race— passgo test ./internal/api/ -run 'TestHooks|TestE2EHooks|TestOIDC|Web3|SAML' -race— passOne unrelated pre-existing failure in this package on my machine
(
TestAuth/TestMaybeLoadUserOrSession/Valid_Session_ID_Claim, atime.Localvs
time.UTCcomparison) reproduces on a cleanmastercheckout and is nottouched by this change.
Closes #2726