Open Closed

Create custom claims and add them to ICurrentUser & ICurrentPrincipalAccessor #930


User avatar
0
Jmg0g0 created

Check 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.

  • ABP Framework version: v4.2.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no (neither multi-tenancy)
  • Exception message and stack trace:
  • Steps to reproduce the issue:

Hi support team, I'm stuck trying to add a claim to the ICurrentUser & ICurrentPrincipalAccessor each time the user login. The idea is get the value from a custom attribute using AppUser entity approach and set a claim ready to use with my claim principal. As I have read several articles around the topic, here and here. However, they seem to be obsoletes please, correct me if I'm wrong, and I not sure how to implement in the current version of ** abp framework community (4.2.1)**:

Trying to visualize the approach, I was thinking on this steps:

  1. Add a new ClaimType using await _identityClaimTypeManager.CreateAsync(claimType)to create a new claimtype. As I understand, this action should be executed only one time to add the type to the database AbpClaimType table.

Correct?, is sedding the database at migration time an option?

and then, I can see two options:

2.1 Get the value from the custom attribute and set the claim each time the user login.

2.2 Create a custom claim using the claimtype created previously and set the value from the attribute (AppUser) and save them in AbpUserClaim table.

does it makes sense for you?, any other options?

At the end, the goal is get the claim from the iCurrentUser like others claims.

Let me know if you need more clarification on what I want to achieve and thanks so much for pointing me out the solution, Jose Manuel Gonzalez


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

    hi

    You can take look at this https://github.com/abpframework/abp/issues/42#issuecomment-576025862

  • User Avatar
    0
    Jmg0g0 created

    Just for anybody with my my doubt, add claims to the ClaimPrincipal doesn't require to add a new ClaimType using await _identityClaimTypeManager.CreateAsync(claimType).

    I can directly add claims to the ClaimPrincipal as maliming mention.

    Appreciated your answer, nice and easy.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19