Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom claims to CurrentUser in abp v4.3.0-rc2 issue #8568

Closed
gerryge opened this issue Apr 11, 2021 · 1 comment
Closed

Add custom claims to CurrentUser in abp v4.3.0-rc2 issue #8568

gerryge opened this issue Apr 11, 2021 · 1 comment

Comments

@gerryge
Copy link
Contributor

gerryge commented Apr 11, 2021

Your ABP Framework version
v4.3.0-rc2
Your User Interface type (Angular/MVC/React... etc.) if the issue is related to a specific UI
MVC
Your database provider(EF Core/MongoDB)
EF Core

Description:
I want to add custom claim to CurrentUser And I do as recommendation in bellow link:
#8073 (comment)
But when login error occurred:
An unhandled exception occurred while processing the request.
InvalidOperationException: only a single identity supported
IdentityServer4.Hosting.IdentityServerAuthenticationService.AssertRequiredClaims(ClaimsPrincipal principal)

image

Steps needed to reproduce the problem.

  1. abp new Acme.BookStore --preview
  2. Add MyClaimsPrincipalContributor(detail see below code) class in Acme.BookStore.Domain project
public class MyClaimsPrincipalContributor : IAbpClaimsPrincipalContributor, ITransientDependency
    {
        public Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
        {
            var claimsIdentity = new ClaimsIdentity();
            claimsIdentity.AddIfNotContains(new Claim("Organization", "OrganizationValue"));
            context.ClaimsPrincipal.AddIdentity(claimsIdentity);

            return Task.CompletedTask;
        }
    }
  1. In BookStoreDomainModule.cs module add below code in ConfigureServices:
      Configure<AbpClaimsServiceOptions>(options =>
      {
          options.RequestedClaims.Add("Organization");
      });
  1. Start the Acme.BookStore.Web project and login in admin/1q2w3E*, then the error occurred.

My demo project(I have changed the Index.cshtml to show the claims):
Acme.BookStore.zip

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

No branches or pull requests

2 participants