Implement single active token providers for email change, email confirmation, and password reset#24926
Merged
Merged
Conversation
…rmation, and password reset
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request implements a "single active token" policy for ASP.NET Core Identity password reset, email confirmation, and change email operations in the ABP Identity module. The implementation uses SHA-256 hash storage to ensure that generating a new token automatically invalidates all previously issued tokens for the same purpose.
Changes:
- Introduces
AbpSingleActiveTokenProvideras a base class that extendsDataProtectorTokenProviderwith hash-based token validation - Adds three concrete token providers (
AbpPasswordResetTokenProvider,AbpEmailConfirmationTokenProvider,AbpChangeEmailTokenProvider) with configurable 2-hour default lifespans - Provides extension methods (
IdentityUserManagerSingleActiveTokenExtensions) for explicit token hash revocation when needed
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| AbpSingleActiveTokenProvider.cs | Base class implementing hash-based single active token validation using SHA-256, with automatic hash storage during generation and comparison during validation |
| AbpPasswordResetTokenProvider.cs | Password reset token provider inheriting from base with provider name "AbpPasswordReset" |
| AbpEmailConfirmationTokenProvider.cs | Email confirmation token provider with detailed documentation about manual revocation requirement |
| AbpChangeEmailTokenProvider.cs | Change email token provider inheriting from base with provider name "AbpChangeEmail" |
| AbpPasswordResetTokenProviderOptions.cs | Configuration class setting 2-hour default lifespan for password reset tokens |
| AbpEmailConfirmationTokenProviderOptions.cs | Configuration class setting 2-hour default lifespan for email confirmation tokens |
| AbpChangeEmailTokenProviderOptions.cs | Configuration class setting 2-hour default lifespan for change email tokens |
| IdentityUserManagerSingleActiveTokenExtensions.cs | Extension methods providing explicit token hash revocation for all three token types |
| AbpIdentityAspNetCoreModule.cs | Module configuration registering the three new providers and setting them as defaults |
| AbpPasswordResetTokenProvider_Tests.cs | Comprehensive test coverage for password reset token generation, validation, invalidation, and persistence |
| AbpEmailConfirmationTokenProvider_Tests.cs | Comprehensive test coverage for email confirmation tokens including explicit revocation testing |
| AbpChangeEmailTokenProvider_Tests.cs | Comprehensive test coverage for change email tokens |
| IdentityUserManagerSingleActiveTokenExtensions_Tests.cs | Unit tests verifying the extension methods correctly remove token hashes |
…ctive token providers and improve token verification logic
…date token handling logic
EngincanV
approved these changes
Feb 24, 2026
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.
Summary
Introduces a "single active token" policy for password reset, email confirmation, and change-email flows by adding three new token providers backed by
AbpSingleActiveTokenProvider.How it works
Each time a new token is generated, a SHA-256 hash is stored in
user.Tokensusing a fixed internal login provider[AbpSingleActiveToken]and a key of{ProviderName}:{purpose}. On validation, the incoming token is re-hashed and compared against the stored hash using a constant-time comparison. Issuing a new token overwrites the hash, immediately invalidating all previously issued tokens for that purpose.The bracketed
[AbpSingleActiveToken]login provider name clearly distinguishes these internal entries from real external login providers (e.g. Google, GitHub) stored in the sameAbpUserTokenstable — following the same convention used by ASP.NET Core Identity's own[AspNetUserStore]internal provider.Example rows in
AbpUserTokens:[AbpSingleActiveToken]AbpPasswordReset:ResetPassword<SHA-256 hex hash>[AbpSingleActiveToken]AbpEmailConfirmation:EmailConfirmation<SHA-256 hex hash>After a successful operation:
ConfirmEmailAsyncdoes not update the SecurityStamp. Callers that require single-use semantics must explicitly revoke the hash:New providers
AbpPasswordResetTokenProviderDefaultAbpEmailConfirmationTokenProviderDefaultAbpChangeEmailTokenProviderDefaultAll three are registered and set as the default providers in
AbpIdentityAspNetCoreModule.Configuration
Token lifespan can be customized via the respective options classes: