Skip to content

amr claim lost after ClaimPrincipal renewal #44666

Open

Description

@jherbert

General inquiry type issue...

amr claim type was added in #10636 and #5783 using the SignInWithClaimsAsync overload on the SignInManager. When the validation interval is hit UserClaimsPrincipalFactory.GenerateClaimsAsync gets called to refresh the ClaimPrincipal claims but the amr claim is lost. Is this by design? We were attempting to put a feature behind 2fa only and using this claim as authorization. If it is suggestions on some possible workarounds? We could add this claim again in our UserClaimsPrincipalFactory. implementation if the user has 2fa enabled with an assumption the user did actually authenticate with it?

Recreation steps

  1. new razor app with indvidual identity
  2. Shorten validation interval so you don't have to wait the default 30 minutes.
builder.Services.Configure<SecurityStampValidatorOptions>(options =>
{
    options.ValidationInterval = TimeSpan.FromSeconds(30);
});
  1. Signin you'll see the amr claim on the user.
  2. Wait 30 seconds, refresh page and amr claim is gone

Activity

  1. added
    area-auth
    on Oct 20, 2022
  2. added
    area-identity
    and removed
    area-auth
    on Oct 20, 2022
  3. blowdart commented on Oct 21, 2022

    @blowdart
    Contributor

    So this is somewhat odd. The amr claim is for the specific sign-in that took place. Once you're into GenerateClaimsAsync you're onto user claims, not claims for the login. I don't think you can know for sure at that point whether an amr claim or not is appropriate.

    We acknowledge this sucks, and we'll think for 8.0 about if/how we could persist it.

  4. added this to the .NET 8 Planning milestone on Oct 21, 2022
  5. reponemec commented on Apr 3, 2023

    @reponemec

    Until a fix is released, can SecurityStampValidatorOptions.OnRefreshingPrincipal handler be used as a workaround? Handler will return lost claims to the game.

  6. jherbert commented on Nov 9, 2023

    @jherbert
    Author

    @reponemec Good suggestion here, OnRefreshingPrincipal has both a CurrentPrincipal and NewPrincipal property here.

  7. added
    pending-ci-rerun
    on Feb 6, 2024
  8. removed
    pending-ci-rerun
    on Feb 6, 2024
  9. added
    pending-ci-rerun
    on Feb 6, 2024
  10. removed
    pending-ci-rerun
    on Feb 13, 2024
  11. anthonymastreanvae commented on May 27, 2025

    @anthonymastreanvae

    We implemented an ITicketStore for the Cookie authentication handler that added several important claims to the claims principal that we require for downstream feature and auditing functionality.

    It was unexpected that the security stamp validator would replace the claims principal.

    We ended up working from this comment to eventually finding this ticket. Now we have a custom OnRefreshingPrincipal handler that merges claims.

    https://github.com/dotnet/aspnetcore/blob/v8.0.16/src/Identity/Core/src/SecurityStampValidator.cs#L109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-identityinvestigate

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions