Open Closed

How to retrieve claims in angular application ? #1236


User avatar
0
kaustubh.kale@ness.com created

ABP Framework version: v4.2.2 UI type: Angular DB provider: EF Core Tiered (MVC) or Identity Server Seperated (Angular): no / yes Exception message and stack trace: Steps to reproduce the issue:

1 . After adding claims for specific user though administration 2. when same user login succesfully then in config-application where we get all details about user like userid,tenatid,in that not geeting claims data.

In Angular application how to get claims data for specific user ?


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

    I saw the claims alreay exists in Local Storage

    @Mehmet How to get it?

  • User Avatar
    0
    Mehmet created

    Hi,

    It can get it like this:

    let idTokenClaims = localStorage.getItem('id_token_claims_obj')
    if (idTokenClaims) {
    idTokenClaims = JSON.parse(idTokenClaims)
    }
    
  • User Avatar
    0
    kaustubh.kale@ness.com created

    Hi Mehmat

    We are not getting claims in localstorage as per you shown above,Their is any other way avialble to get claims in angular application.

    If you want any other information then let me know.

  • User Avatar
    0
    Mehmet created

    Hi,

    Can you share the local storage with me after logging in? Can you also share the oAuthConfig object in the environment?

  • User Avatar
    0
    kaustubh.kale@ness.com created

    Enviorment.ts

    export const environment = { production: false, application: { name: 'Litmus' }, oAuthConfig: { issuer: 'https://localhost:44350', clientId: 'Litmus_App', dummyClientSecret: '1q2w3e*', scope: 'Litmus ProfileManagement InvoiceManagement FinanceManagement', showDebugInformation: true, oidc: false, requireHttps: true }, apis: { default: { url: 'https://localhost:44359' }, profileManagement: { url : 'https://localhost:44398/profile' }, invoiceManagement: { url : 'https://localhost:44324/invoice' } }, localization: { defaultResourceName: 'Litmus' } };

    Localstorage:

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The access_token also contains user claims. The id_token only available when you're using openid login.

    You can use third library to decode that.

    constructor(
        private oauthService: OAuthService
      ) {
        console.debug('access-token', this.oauthService.getAccessToken());
      }
    

    https://www.npmjs.com/package/jwt-claims https://www.npmjs.com/package/jwt-simple

  • User Avatar
    0
    kaustubh.kale@ness.com created

    Hi Mehmat

    Sorry for inconvieniance I put wrong ABP Version for above issue. The current version is ABP Framework version: v3.0.4

    let me know for this version solution is same or not.

  • User Avatar
    0
    Mehmet created

    Hi

    Did you try @maliming's suggesion?

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

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