Hi @Zambre, Akash,
Based on your query, here is my understanding: you would like to add optional claims to check the UPN in id token and would like to know how to get role claims.
As per your description, you are not receiving UPN in ID token. UPN has different names based on the endpoint version you are using to retrieve the token. ID token can be retrieved using v1 or v2 version tokens.
unique_name
: Only present in v1.0 tokens. Provides a human readable value that identifies the subject of the token. This value isn't guaranteed to be unique within a tenant and should be used only for display purposes
preferred_username
: The primary username that represents the user. It could be an email address, phone number, or a generic username without a specified format. Its value is mutable and might change over time. Since it's mutable, this value can't be used to make authorization decisions. It can be used for username hints and in human-readable UI as a username. The profile
scope is required to receive this claim. Present only in v2.0.
Please take a look at the following document for more information: ID token claims reference
If you would like to retrieve app roles to your application, please follow this document: Add app roles to your application and receive them in the token.These app roles we are talking here are assigned at app registrations but not the roles the user is assigned. While assigning a user to the application, it will provide you the options of roles created by you in App roles of the application only. In order to retrieve Microsoft Entra directory roles, you can configure the roles using the following document: Configure group claims and app roles in tokens.
I hope this information is helpful. Please feel free to reach out if you have any further questions.
If the answer is helpful, please click "Accept Answer" and kindly "upvote it". If you have extra questions about this answer, please click "Comment"