Skip to content

Enhance LinkUserTokenProvider with single-active policy and consent helpers#25450

Merged
ebicoglu merged 5 commits into
devfrom
enhance-link-user
Jun 1, 2026
Merged

Enhance LinkUserTokenProvider with single-active policy and consent helpers#25450
ebicoglu merged 5 commits into
devfrom
enhance-link-user

Conversation

@maliming

Copy link
Copy Markdown
Member

Upgrade LinkUserTokenProvider to derive from AbpSingleActiveTokenProvider with a dedicated AbpLinkUserTokenProviderOptions (default 10 min lifespan, configurable per project). Add RemoveLinkUserTokenAsync extension on IdentityUserManager.

Add three consent payload helpers on IdentityLinkUserManager (SetLinkConsentAsync / GetLinkConsentAsync / RemoveLinkConsentAsync) backed by the user.Tokens slot [AbpLinkUserConsent]/Consent. Framework owns the storage, callers own the payload format.

Companion to volosoft/volo#22357.

…elpers

- Make LinkUserTokenProvider derive from AbpSingleActiveTokenProvider
- Add AbpLinkUserTokenProviderOptions with 10 min default lifespan
- Add RemoveLinkUserTokenAsync extension on IdentityUserManager
- Add SetLinkConsentAsync/GetLinkConsentAsync/RemoveLinkConsentAsync on IdentityLinkUserManager backed by user.Tokens slot [AbpLinkUserConsent]/Consent
Copilot AI review requested due to automatic review settings May 19, 2026 08:52
@maliming maliming added this to the 10.5-preview milestone May 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates ABP Identity’s link-user flow by moving LinkUserTokenProvider onto the framework’s single-active token infrastructure (so only the most recently issued token remains valid) and adds helpers for invalidation and storing a per-user “link consent” payload in IdentityUser.Tokens.

Changes:

  • Switch LinkUserTokenProvider to derive from AbpSingleActiveTokenProvider and introduce AbpLinkUserTokenProviderOptions with a 10-minute default lifespan.
  • Add IdentityUserManager.RemoveLinkUserTokenAsync to invalidate previously issued link-user tokens by removing the stored hash.
  • Add consent payload helpers (SetLinkConsentAsync / GetLinkConsentAsync / RemoveLinkConsentAsync) on IdentityLinkUserManager plus corresponding tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityLinkUserManager_Tests.cs Adds test coverage for link-consent persistence, overwrite, and removal behaviors.
modules/identity/test/Volo.Abp.Identity.AspNetCore.Tests/Volo/Abp/Identity/AspNetCore/LinkUserTokenProvider_Tests.cs Refactors tests to reuse AbpSingleActiveTokenProviderTestBase and adds invalidation test for RemoveLinkUserTokenAsync.
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityLinkUserManager.cs Implements consent payload helpers using IdentityUser.Tokens.
modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/LinkUserTokenProviderConsts.cs Adds constants for consent token storage keys.
modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/LinkUserTokenProvider.cs Updates provider to single-active token policy base class and injects required dependencies.
modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/IdentityUserManagerSingleActiveTokenExtensions.cs Adds RemoveLinkUserTokenAsync helper to remove the stored hash entry.
modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpLinkUserTokenProviderOptions.cs Introduces dedicated token provider options (name + default lifespan).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.14876% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.36%. Comparing base (521f6c9) to head (11eef28).
⚠️ Report is 91 commits behind head on dev.

Files with missing lines Patch % Lines
...Volo/Abp/Identity/IdentityLinkUserManager_Tests.cs 0.00% 67 Missing ⚠️
...omain/Volo/Abp/Identity/IdentityLinkUserManager.cs 92.30% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #25450      +/-   ##
==========================================
- Coverage   49.40%   49.36%   -0.04%     
==========================================
  Files        3670     3671       +1     
  Lines      123598   123718     +120     
  Branches     9453     9456       +3     
==========================================
+ Hits        61062    61072      +10     
- Misses      60705    60830     +125     
+ Partials     1831     1816      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Use UserManager.SetAuthenticationTokenAsync/GetAuthenticationTokenAsync/
  RemoveAuthenticationTokenAsync so the Tokens collection is loaded via
  IdentityUserStore.EnsureCollectionLoadedAsync instead of relying on the
  GetByIdAsync(includeDetails) convention.
- Add a RemoveLinkUserTokenAsync(manager, user, purpose) overload to invalidate
  tokens issued for purposes other than LinkUserTokenPurpose.
- Add a cross-UnitOfWork persistence test for SetLink/Get/Remove ConsentAsync.
- Drop the unused IdentityLinkUserRepository field from LinkUserTokenProvider_Tests.
@maliming

Copy link
Copy Markdown
Member Author

@copilot please review again

Copilot AI commented May 20, 2026

Copy link
Copy Markdown
Contributor

@copilot please review again

Done. I addressed the open review points and pushed commit d095f56d: consent token helpers now run inside a UoW ([UnitOfWork] on set/get/remove), and the RemoveLinkUserTokenAsync XML doc now explicitly states it targets the default purpose overload. Focused tests for IdentityLinkUserManager_Tests and LinkUserTokenProvider_Tests pass, and parallel validation is clean.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

- SetLinkConsentAsync uses FindByIdAsync + null no-op, matching the
  missing-user behaviour of Get/RemoveLinkConsentAsync.
- Decorate Set/Get/RemoveLinkConsentAsync with [UnitOfWork] so the
  underlying IdentityUserStore.GetTokenAsync can EnsureCollectionLoaded
  the user.Tokens collection (fixes the CI failure on
  GetLinkConsentAsync_Should_Return_Null_When_No_Consent_Written).
- Clarify LinkUserTokenProvider XML doc to note that the single-active
  policy is enforced per purpose (matches AbpSingleActiveTokenProvider).
- Rename LinkUserTokenProvider_Should_Be_Register to *_Registered for
  consistency with sibling token-provider tests.
- Add tests covering: (a) RemoveLinkUserTokenAsync(purpose) only
  invalidates the requested purpose, and (b) same-purpose GenerateLink
  TokenAsync invalidates the previously issued token.
@maliming maliming changed the base branch from rel-10.4 to dev May 20, 2026 04:53
@maliming maliming requested review from ebicoglu and yagmurcelk May 20, 2026 05:21
@gizemmutukurt gizemmutukurt requested review from oykuermann and removed request for yagmurcelk May 22, 2026 05:14
@oykuermann oykuermann removed their request for review May 22, 2026 06:23
@oykuermann

Copy link
Copy Markdown
Contributor

This PR will be tested on 10.5.0-rc.1

@ebicoglu ebicoglu merged commit c02d7ef into dev Jun 1, 2026
2 of 4 checks passed
@ebicoglu ebicoglu deleted the enhance-link-user branch June 1, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants