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)
-
0
Hi,
Can you try this?
Configure<AbpClaimsServiceOptions>(options=> { options.RequestedClaims.Add("OrganizationId") })
-
0
It's working now~ thanks