Skip to content

Add secure email verification registration workflow - #2

Merged
hifeamin merged 18 commits into
mainfrom
feature/account-verification
Nov 19, 2026
Merged

hifeamin merged 18 commits into
mainfrom
feature/account-verification

Conversation

@hifeamin

@hifeamin hifeamin commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements the agreed generic verification infrastructure, with email registration as the first workflow.

  • Adds generic verification requests, purposes/channels, secure code generation/protection, opaque public handles, attempt limits, resend cooldowns, destination-level send limits, and atomic persistence contracts.
  • Adds the EF Core relational store.
  • Changes public registration to create pending accounts, verify by code, resend, and issue tokens only after successful verification.
  • Adds separate administrator provisioning that creates already-confirmed users without issuing tokens.
  • Keeps external-provider sign-in free of a second verification step by default; verification can be required with RequireEmailVerificationForExternalLogins.
  • Tightens external-provider token validation and prevents automatic linking to an existing account based only on email.
  • Adds a relational SQLite sample, documentation, tests, and one consolidated GitHub Actions workflow.

Email delivery

The core library defines IVerificationSender<TUser, TKey> but deliberately does not implement an email/SMS provider. The basic sample contains an example MailKit SMTP sender. MailKit is a sample-only dependency; consumers must implement and register their own sender.

CI and publishing

The redundant .github/workflows/ci.yml and the separate MailKit library project have been removed. The existing publish.yml is the single workflow:

  • Pull requests targeting main run the test suite.
  • Pushes to main run the test suite.
  • Version-tag pushes run tests, pack NuGet packages, and publish them through the existing OIDC-based NuGet workflow.
  • Manual dispatch remains available.

Breaking changes and setup

  • Major-version change: immediate-token IUserAccountService.RegisterAsync has been removed in favor of IRegistrationService<TUser, TKey>.
  • Applications must call AddVerificationServices, register a durable IVerificationRequestStore<TKey> and their own sender, and add verification entities to a relational DbContext.
  • Create and apply an EF Core migration after adding AddVerificationRequestEntity<TKey>().
  • Configure persistent/shared ASP.NET Core Data Protection keys in production.
  • MapAdminUserApi requires the Administrator role by default or a named authorization policy.
  • RegistrationVerificationResponse.Message is a generic client-facing status message; it does not reveal whether the email already belongs to an account or whether an email was actually sent.

Verification

  • Latest GitHub Actions run: passed.
  • The existing publish.yml successfully ran the test suite on the updated PR commit.
  • A local build was not run in this environment.

Review notes

Please pay particular attention to the external-provider trust policy, EF atomicity across the supported relational provider, and the major-version registration migration.

@hifeamin
hifeamin marked this pull request as ready for review November 18, 2026 23:11

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. I addressed the comments in commit d2672dbf7266800512440ec7626d61f8610b25b7.

Applied

  • Replaced direct new HttpClient() in the Facebook provider with IHttpClientFactory; registered the HTTP client factory in the authentication builder.
  • Added ILogger diagnostics to the Facebook, Google, and Microsoft external login providers. Token values and token-bearing request URLs are not logged.
  • Clarified the confirmed-account registration path: confirmed accounts are not modified and do not trigger another verification email; the response remains generic to prevent account enumeration.
  • Updated RegistrationVerificationResponse.Message to: “If this email address can be registered, check your inbox for a verification message.”

Design decisions retained

  • Custom Name/profile fields: the default updater intentionally copies only standard, explicitly permitted Identity fields. Blindly copying every custom property from an unauthenticated registration request could overwrite tenant, authorization, or account-security data. The README now includes an IUserRegistrationUpdater<AppUser> example showing how to explicitly update DisplayName and other safe profile fields.
  • SQLite: retained because the verification EF store depends on relational transactions and atomic conditional updates; EF Core InMemory cannot provide those guarantees. This is documented in the sample.
  • EnsureCreated: retained only for local Development bootstrap because the sample has no checked-in migration files. EnsureCreated creates the current model schema but does not apply future migrations. The sample and README now state that production applications should use EF Core migrations.

The updated workflow is running for the new commit. I will not merge the PR.

Copy link
Copy Markdown
Collaborator Author

Implemented in commit dfda3d5531658ce6c59cea939c231a9077097a04.

  • Removed IUserRegistrationUpdater<TUser>.
  • Removed DefaultUserRegistrationUpdater<TUser, TKey>.
  • Removed the updater registration from AddVerificationServices().
  • Simplified RegistrationService so an existing pending account is reused without modifying any of its fields. This applies both to normal repeat registration and the concurrent-registration race path.
  • Updated tests to assert that an existing pending user is reused unchanged and that no Identity update is performed.
  • Updated the root README to describe this behavior and removed the custom updater example.

This also means a repeated registration does not change the existing user's username, phone number, email, password, or custom properties. If the user needs to change those values, that should be handled by a separate authenticated account-management or recovery flow.

@hifeamin
hifeamin merged commit a04f92c into main Nov 19, 2026
3 checks passed
@hifeamin
hifeamin deleted the feature/account-verification branch November 20, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant