Azure AD Application Role in Access Token

Rahul Yadav 0 Reputation points
2023-09-17T17:51:01.1+00:00

I have registered an application on AD, created the user and application roles after this I assign the application roles to the user. I want application role to be part of access token may be in claims. How can I achieve this please help.

Azure Role-based access control
Azure Role-based access control
An Azure service that provides fine-grained access management for Azure resources, enabling you to grant users only the rights they need to perform their jobs.
Microsoft Security | Microsoft Authenticator
Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Akshay-MSFT 18,011 Reputation points Microsoft Employee Moderator
    2023-10-04T10:04:41.5166667+00:00

    @Rahul Yadav

    Thank you for time and patience while posting your query on Microsoft Q&A. From above description I could understand that you are looking for way to get application Roles assigned to user in the oauth tokens as claims.

    Please do correct me if this is not the case by responding in the comments section:

    This could be achieved by as per Add app roles to your application and receive them in the token, also a similar request has been answered here:

    https://learn.microsoft.com/en-us/answers/questions/1123326/how-to-get-user-app-role-when-singning-using-oauth

    To extract roles of user you need to have them configured as per : Add app roles to your application and receive them in the token.

    • Ensure that application have Implicit and hybrid grants flow enabled:

    270492-image.png

    • The endpoint must be hitting organization endpoint and not common/personal, as they would not emit the roles. Given is the example

    https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize?
    client_id={Application ID}
    &response_type=code&id_token
    &redirect_uri=http://localhost/myapp/
    &response_mode=query
    &scope=openid&https://graph.microsoft.com/mail.read
    &state=12345
    &nonce=abcde

    • Extract the code from request you sent above:

    270453-image.png

    • The id_token will contain the user app roles assigned to the guest user and endpoint with tenant id:

    270455-image.png

    Thanks,

    Akshay Kaushik

    Please "Accept the answer" (Yes), and share your feedback if the suggestion answers you’re your query. This will help us and others in the community as well.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.