Starts in:
1 DAY
22 HRS
13 MIN
8 SEC
Starts in:
1 D
22 H
13 M
8 S
Open Closed

IAbpClaimsPrincipalContributor doesn't work in microservice project? #2684


User avatar
0
mc86 created

https://support.abp.io/QA/Questions/1433/How-to-add-extra-information-to-CurrentUserCheck the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v5.1
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

https://docs.abp.io/en/abp/latest/Authorization#advanced-topics https://support.abp.io/QA/Questions/1433/How-to-add-extra-information-to-CurrentUser Hi I want to get currentuser's OU ID, I followed the doc add codes below in my service domain project. then use this.CurrentUser.FindClaim("OrganizationId"); to get OrganizationId in my blazor project. but it always is null. what do i miss?

public class OrgClaimsPrincipalContributor : IAbpClaimsPrincipalContributor, ITransientDependency
    {
        public async Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
        {
            //var identity = context.ClaimsPrincipal.Identities.FirstOrDefault();
            //var userId = identity?.FindUserId();
            //if (userId.HasValue)
            //{
            //    //var userService = context.ServiceProvider.GetRequiredService<IdentityUserAppService>(); //Your custom service
            //    //var OrgList = await userService.GetOrganizationUnitsAsync(userId.Value);
            //    //var Org = OrgList.ToList().FirstOrDefault();
            //    //if (Org != null)
            //    //{
            //    //    var Claim = new Claim("OrganizationId", "123");
            //    //    identity.AddClaim(Claim);
            //    //}

            //    var Claim = new Claim("OrganizationId", "123");
            //    identity.AddClaim(Claim);
            //}

            var identity = context.ClaimsPrincipal.Identities.FirstOrDefault();
            identity.AddClaim(new Claim("OrganizationId", "OrganizationValue"));
        }
    }
var orgid = this.CurrentUser.FindClaim("OrganizationId");

2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Can you try this?

    Configure<AbpClaimsServiceOptions>(options=>
    {
        options.RequestedClaims.Add("OrganizationId")
    })
    
  • User Avatar
    0
    mc86 created

    It's working now~ thanks

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06