Repository navigation
Harden external login lifecycle and account linking - #12
Merged
Merged
Conversation
Add a protected virtual ValidatePayloadAsync to GoogleExternalLoginProvider so the provider's own handling can be tested without reaching Google's certificate endpoint. The default implementation is unchanged: it calls GoogleJsonWebSignature.ValidateAsync with the configured client ID as the only accepted audience. The provider now also returns null if validation yields no payload. Add ExternalLoginProviderValidationTest covering invalid signature, issuer and audience mismatch, expiry, unverified email and missing subject: - Microsoft: real JWT validation against stubbed metadata and signing keys. - Facebook: stubbed Graph API responses (invalid token, app mismatch, expiry, missing and mismatched subject, invalid configured app id). - Google: simulated library rejection plus subject, unverified email, missing configuration and cancellation handling. Not built or run: the authoring environment has no .NET SDK. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CaSpXU2uU4P75CdgjJ6NR
…unconfirmed accounts Move external login account resolution out of UserAccountService into a resolve-only IExternalLoginService. Untrusted provider emails are ignored (not used for lookup, not stored). A trusted email on an unconfirmed account removes its password and revokes sessions before the login is attached. A newly created account is deleted if its login cannot be attached. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CaSpXU2uU4P75CdgjJ6NR
Introduce ExternalLoginEmailTrustMode (Verified, Always, Never) configured per provider through EmailTrust and carried on ExternalLoginProviderResult. The default policy applies it. Defaults: Google Verified, Facebook Always, Microsoft Never (Microsoft email claims are mutable and not proof of mailbox ownership). Custom providers and policies keep the previous Verified behavior. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CaSpXU2uU4P75CdgjJ6NR
Extend IExternalLoginService with LinkAsync, UnlinkAsync and ListLoginsAsync and expose them as GET logins, POST logins/link and POST logins/unlink in the account management API (mapped only when the service is registered). Linking requires re-authentication with the current password (counted toward lockout) or a fresh token of an already linked identity, does not require the provider email to match, allows one identity per provider per account and rejects identities that belong to another account. Concurrent links are re-checked and undone. Unlinking is refused when it would remove the last usable authentication method, re-checks and restores the login if a concurrent request raced it, and revokes refresh tokens. IUserPasswordManager gains a HasPasswordAsync default interface member that fails closed for custom managers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CaSpXU2uU4P75CdgjJ6NR
Describe per-provider EmailTrust modes and defaults (with the Microsoft warning), how an external login resolves to an account including neutralizing unconfirmed accounts, the link/unlink/list endpoints and step-up re-authentication, the non-transactional crash-window limitation and upgrade notes. Update the Basic sample settings and ReadMe, and refresh README text that described the previous behavior. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CaSpXU2uU4P75CdgjJ6NR
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.
Context
External login previously resolved accounts inside
UserAccountService, matched existing accounts by email only through a trust policy that rejected most providers, left half-created accounts behind on failure, and offered no way for a signed-in user to link or unlink a provider. This PR hardens the whole external login lifecycle: account resolution, email trust, linking, unlinking, and listing. It adds no schema changes or migrations.Summary of changes
Delivered as five reviewable commits:
b0dac61). Google, Microsoft and Facebook tests cover invalid signature, issuer/audience mismatch, expiry, missing subject, unverified email, invalid config and cancellation.GoogleExternalLoginProvidergets a protected virtualValidatePayloadAsyncso library rejection can be simulated.IExternalLoginService<TUser>(f0b7bea).UserAccountService.ExternalLoginAsyncdelegates to it. Untrusted emails are ignored (not used for lookup, not stored). A trusted email that matches an unconfirmed account first neutralizes it (remove password, revoke refresh tokens), then links the login and confirms the email. A newly created account is deleted if its login cannot be attached. All failures return the same genericExternalAuthenticationFailed400.ae353db). NewExternalLoginEmailTrustMode(Verified,Always,Never) set through each provider'sEmailTrustoption and carried onExternalLoginProviderResult. Defaults: GoogleVerified, FacebookAlways, MicrosoftNever.7b77f21).GET logins,POST logins/link,POST logins/unlinkinMapAccountManagementApi, mapped only whenIExternalLoginService<TUser>is registered.2b5cb1d). README (trust modes, account resolution, endpoints, limits, upgrade notes), Basic sampleappsettings.jsonand ReadMe.Architectural decisions
IExternalLoginService<TUser>is new and optional.UserAccountServicekeeps all existing constructors; when no service is registered it composes one from its existing dependencies. The 16-parameter constructor signature is preserved so existing explicit calls still bind to it, while DI selects the new constructor with optional dependencies.ISignInManagerand user-management responsibilities.ISignInManageris used only for the password re-authentication check.IUserPasswordManager<TUser>gainsHasPasswordAsyncas a default interface member returningfalse, so custom managers still compile and fail closed.POST password, usernames (PROVIDER_subjectfallback, trusted email otherwise),RequireEmailVerificationForExternalLogins.Security considerations
commonendpoint is multi-tenant, so Microsoft isNeverby default. The README warns before enablingAlways.Tests
New or updated:
ExternalLoginProviderValidationTest,ExternalLoginServiceTest(resolve),ExternalLoginLinkingTest(link, unlink, list, races, fail-closed),AccountExternalLoginEndpointTest(mapping, auth metadata, status codes, sanitized bodies),ExternalLoginEmailTrustPolicyTest,UserAccountServiceTest. FourUserAccountServiceTestcases changed because behavior changed (untrusted email now creates an account without it; a failed link after create now deletes the created user).Build and test status (accurate):
Breaking changes and migration notes
No schema changes or migrations, and no changes to existing constructors or
POST password. Behavior changes to review:EmailTrust = ExternalLoginEmailTrustMode.Neverto keep the old behavior.RequireEmailVerificationForExternalLogins = truewhere a verified email is required.IUserPasswordManager<TUser>implementations should implementHasPasswordAsync; until then unlinking is refused and password re-authentication is rejected.Known limitations
https://claude.ai/code/session_017CaSpXU2uU4P75CdgjJ6NR
Generated by Claude Code