Add app roles and get them from a token - Microsoft Entra (2024)

  • Article

Role-based access control (RBAC) is a popular mechanism to enforce authorization in applications. RBAC allows administrators to grant permissions to roles rather than to specific users or groups. The administrator can then assign roles to different users and groups to control who has access to what content and functionality.

By using RBAC with application role and role claims, developers can securely enforce authorization in their apps with less effort.

Another approach is to use Azure Active Directory (Azure AD) groups and group claims as shown in the active-directory-aspnetcore-webapp-openidconnect-v2 code sample on GitHub. Azure AD groups and application roles aren't mutually exclusive; they can be used together to provide even finer-grained access control.

Declare roles for an application

You define app roles by using the Azure portal during the app registration process. App roles are defined on an application registration representing a service, app or API. When a user signs in to the application, Azure AD emits a roles claim for each role that the user or service principal has been granted. This can be used to implement claim-based authorization. App roles can be assigned to a user or a group of users. App roles can also be assigned to the service principal for another application, or to the service principal for a managed identity.

Currently, if you add a service principal to a group, and then assign an app role to that group, Azure AD doesn't add the roles claim to tokens it issues.

App roles are declared using App roles UI in the Azure portal:

The number of roles you add counts toward application manifest limits enforced by Azure AD. For information about these limits, see the Manifest limits section of Azure Active Directory app manifest reference.

App roles UI

To create an app role by using the Azure portal's user interface:

  1. Sign in to the Azure portal.

  2. If you have access to multiple tenants, use the Directories + subscriptions filter Add app roles and get them from a token - Microsoft Entra (1) in the top menu to switch to the tenant that contains the app registration to which you want to add an app role.

  3. Search for and select Azure Active Directory.

  4. Under Manage, select App registrations, and then select the application you want to define app roles in.

  5. Select App roles, and then select Create app role.

    Add app roles and get them from a token - Microsoft Entra (2)

  6. In the Create app role pane, enter the settings for the role. The table following the image describes each setting and their parameters.

    Add app roles and get them from a token - Microsoft Entra (3)

    FieldDescriptionExample
    Display nameDisplay name for the app role that appears in the admin consent and app assignment experiences. This value may contain spaces.Survey Writer
    Allowed member typesSpecifies whether this app role can be assigned to users, applications, or both.

    When available to applications, app roles appear as application permissions in an app registration's Manage section > API permissions > Add a permission > My APIs > Choose an API > Application permissions.

    Users/Groups
    ValueSpecifies the value of the roles claim that the application should expect in the token. The value should exactly match the string referenced in the application's code. The value can't contain spaces.Survey.Create
    DescriptionA more detailed description of the app role displayed during admin app assignment and consent experiences.Writers can create surveys.
    Do you want to enable this app role?Specifies whether the app role is enabled. To delete an app role, deselect this checkbox and apply the change before attempting the delete operation.Checked
  7. Select Apply to save your changes.

Assign users and groups to roles

Once you've added app roles in your application, you can assign users and groups to the roles. Assignment of users and groups to roles can be done through the portal's UI, or programmatically using Microsoft Graph. When the users assigned to the various app roles sign in to the application, their tokens will have their assigned roles in the roles claim.

To assign users and groups to roles by using the Azure portal:

  1. Sign in to the Azure portal.
  2. In Azure Active Directory, select Enterprise applications in the left-hand navigation menu.
  3. Select All applications to view a list of all your applications. If your application doesn't appear in the list, use the filters at the top of the All applications list to restrict the list, or scroll down the list to locate your application.
  4. Select the application in which you want to assign users or security group to roles.
  5. Under Manage, select Users and groups.
  6. Select Add user to open the Add Assignment pane.
  7. Select the Users and groups selector from the Add Assignment pane. A list of users and security groups is displayed. You can search for a certain user or group and select multiple users and groups that appear in the list.
  8. Once you've selected users and groups, select the Select button to proceed.
  9. Select Select a role in the Add assignment pane. All the roles that you've defined for the application are displayed.
  10. Choose a role and select the Select button.
  11. Select the Assign button to finish the assignment of users and groups to the app.

Confirm that the users and groups you added appear in the Users and groups list.

Assign app roles to applications

Once you've added app roles in your application, you can assign an app role to a client app by using the Azure portal or programmatically by using Microsoft Graph.

When you assign app roles to an application, you create application permissions. Application permissions are typically used by daemon apps or back-end services that need to authenticate and make authorized API call as themselves, without the interaction of a user.

To assign app roles to an application by using the Azure portal:

  1. Sign in to the Azure portal.
  2. In Azure Active Directory, select App registrations in the left-hand navigation menu.
  3. Select All applications to view a list of all your applications. If your application doesn't appear in the list, use the filters at the top of the All applications list to restrict the list, or scroll down the list to locate your application.
  4. Select the application to which you want to assign an app role.
  5. Select API permissions > Add a permission.
  6. Select the My APIs tab, and then select the app for which you defined app roles.
  7. Select Application permissions.
  8. Select the role(s) you want to assign.
  9. Select the Add permissions button complete addition of the role(s).

The newly added roles should appear in your app registration's API permissions pane.

Grant admin consent

Because these are application permissions, not delegated permissions, an admin must grant consent to use the app roles assigned to the application.

  1. In the app registration's API permissions pane, select Grant admin consent for <tenant name>.
  2. Select Yes when prompted to grant consent for the requested permissions.

The Status column should reflect that consent has been Granted for <tenant name>.

Usage scenario of app roles

If you're implementing app role business logic that signs in the users in your application scenario, first define the app roles in App registrations. Then, an admin assigns them to users and groups in the Enterprise applications pane. These assigned app roles are included with any token that's issued for your application, either access tokens when your app is the API being called by an app or ID tokens when your app is signing in a user.

If you're implementing app role business logic in an app-calling-API scenario, you have two app registrations. One app registration is for the app, and a second app registration is for the API. In this case, define the app roles and assign them to the user or group in the app registration of the API. When the user authenticates with the app and requests an access token to call the API, a roles claim is included in the token. Your next step is to add code to your web API to check for those roles when the API is called.

To learn how to add authorization to your web API, see Protected web API: Verify scopes and app roles.

App roles vs. groups

Though you can use app roles or groups for authorization, key differences between them can influence which you decide to use for your scenario.

App rolesGroups
They're specific to an application and are defined in the app registration. They move with the application.They aren't specific to an app, but to an Azure AD tenant.
App roles are removed when their app registration is removed.Groups remain intact even if the app is removed.
Provided in the roles claim.Provided in groups claim.

Developers can use app roles to control whether a user can sign in to an app or an app can obtain an access token for a web API. To extend this security control to groups, developers and admins can also assign security groups to app roles.

App roles are preferred by developers when they want to describe and control the parameters of authorization in their app themselves. For example, an app using groups for authorization will break in the next tenant as both the group ID and name could be different. An app using app roles remains safe. In fact, assigning groups to app roles is popular with SaaS apps for the same reasons as it allows the SaaS app to be provisioned in multiple tenants.

Next steps

Learn more about app roles with the following resources.

Add app roles and get them from a token - Microsoft Entra (2024)

FAQs

Add app roles and get them from a token - Microsoft Entra? ›

Assign the role to the app registration

Note the subscription ID, which you will need when you create an Azure deployment. Click +Add, and then click Add role assignment. In the Role tab, search for the RBAC role you created, and then click View. Click the Members tab, and ensure the RBAC role you created is listed.

How do I add a role to enterprise app? ›

Assign the role to a user using the Azure portal
  1. Sign in to the Azure portal.
  2. Select Azure Active Directory > Roles and administrators.
  3. Select the Grant permissions to manage user and group assignments role.
  4. Select Add assignment, select the desired user, and then click Select to add role assignment to the user.
Mar 9, 2023

How do I assign RBAC to app registration? ›

Assign the role to the app registration

Note the subscription ID, which you will need when you create an Azure deployment. Click +Add, and then click Add role assignment. In the Role tab, search for the RBAC role you created, and then click View. Click the Members tab, and ensure the RBAC role you created is listed.

How do I add permissions to enterprise application Azure? ›

Sign in to the Azure portal with one of the roles listed in the prerequisites section. Select Azure Active Directory, and then select Enterprise applications. Select the application to which you want to grant tenant-wide admin consent, and then select Permissions.

How do I get Microsoft ad token? ›

There are two steps to acquire an Azure AD access token using the authorization code flow.
  1. Request an authorization code, which launches a browser window and asks for Azure user login. The authorization code is returned after the user successfully logs in.
  2. Use the authorization code to acquire the Azure AD access token.

How do I add API Permissions to enterprise app? ›

From the left pane of the window, under the Manage menu group, select API permissions. This reveals the Configured permissions for your app registration. Select Add a permission.

How do I register an app in Active Directory? ›

In the Azure portal, select Azure Active Directory in the left pane and select App registrations and click on New registration. In the Register an application page, enter your application's registration information: In the Name section, enter a meaningful application name that will be displayed to the users.

What is the difference between application permissions and delegated permissions? ›

Delegated permissions: Also called scopes, allow the application to act on behalf of the signed-in user. Application permissions: Also called app roles, allow the app to access data on its own, without a signed-in user.

How can you implement role based access control RBAC? ›

RBAC implementation
  1. Inventory your systems. Figure out what resources you have for which you need to control access, if you don't already have them listed. ...
  2. Analyze your workforce and create roles. ...
  3. Assign people to roles. ...
  4. Never make one-off changes. ...
  5. Audit.
Jan 2, 2019

What is the difference between App registration and enterprise application? ›

In some cases, people even use both terms interchangeably. But, App registration is simply the actual application object where you configure application settings. Whereas Enterprise Application is a representation of the application within a directory.

How do I add Permissions to a custom role in Azure? ›

Add or remove permissions
  1. To add permissions, click Add permissions to open the Add permissions pane. ...
  2. In the Search for a permission box, type a string to search for permissions. ...
  3. Click a resource provider card that might have the permissions you want to add to your custom role, such as Microsoft Billing.
Apr 5, 2023

How do I create a custom enterprise application in Azure? ›

Create an Enterprise Application
  1. Log in to Microsoft Azure using the obtained credentials. ...
  2. From the list of available Azure services, choose Azure Active Directory.
  3. Click on Enterprise applications in the left pane.
  4. Click + New application.
  5. Click + Create your own application.
  6. Enter a name for the application.

What is the difference between Microsoft ID token and access token? ›

Third-party applications are intended to understand ID tokens. ID tokens shouldn't be used for authorization purposes. Access tokens are used for authorization. The claims provided by ID tokens can be used for UX inside your application, as keys in a database, and providing access to the client application.

What is the difference between identity token and access token? ›

Unlike access tokens, which are opaque objects that cannot be inspected by the application, ID tokens are meant to be inspected and used by the application. Information from the token, such as Who signed the token or the identity for whom the ID token was issued, is available for use by the application.

How do I get an access token from an authorization server? ›

After you add the authorization profile, you need to get access token from the server. In this tutorial, we get it by using the Authorization Code grant method: Click Get Token. In the subsequent dialog, enter Client Identification and Secret, Authorization URI, Access Token URI and Redirect URI.

How to request and grant Permissions to Azure APIs for the Azure App for Exchange Online? ›

Checking Permissions for Office 365 Exchange Online API
  1. Sign in to the Azure portal.
  2. Go to Azure Active Directory > App registrations, and select an application.
  3. Select API permissions > Add a permission > APIs my organization uses.
Aug 19, 2022

What is the difference between API Permissions and expose an API? ›

Expose API means this app represents the API you need to access. API Permission means this app will be used to make requests to web API app or Microsoft Graph resources.

How do I create an API permission? ›

Go to Dashboard > Applications > APIs and click the name of the API to view. Go to the Permissions tab and enter a permission name and description for the permission you want to add. Be sure not to use any reserved permission names (see Reserved names section).

Is there a bot that automatically assigns Roles? ›

The MEE6 bot will automatically assign roles in discord when a user clicks on a discord reaction or button. Here is a step-by-step guide to automate user permission assignments for your server by using the MEE6 bot's Reaction Roles.

How do I change Roles in a group? ›

Using Google Groups
  1. Point to each member whose settings you want to change and check the box next to their name.
  2. Above the list on the right, click Change role .
  3. Select the new role.

How do you use Carl bot for Roles? ›

How to Add Reaction Roles to Discord
  1. Download Carl-bot.
  2. Authorize Carl-bot to join your server.
  3. Choose what permissions to give to Carl-bot.
  4. Navigate to the “Reaction Roles” section and start adding your emojis.
  5. Assign emojis to all of your roles, then click create.
Jun 16, 2022

How does an application authenticate with Active Directory? ›

Here's How the Authentication Process Goes:

The client requests an authentication ticket from the AD server. The AD server returns the ticket to the client. The client sends this ticket to the Endpoint Server. The Server then returns an acknowledgment of authentication to the client.

What is Active Directory for Authentication and authorization? ›

Azure Active Directory (Azure AD) is a centralized identity provider in the cloud. Delegating authentication and authorization to it enables scenarios such as: Conditional Access policies that require a user to be in a specific location. Multi-Factor Authentication which requires a user to have a specific device.

What is Microsoft app registration? ›

Registering your application establishes a trust relationship between your app and the Microsoft identity platform. The trust is unidirectional: your app trusts the Microsoft identity platform, and not the other way around. Once created, the application object cannot be moved between different tenants.

What is the difference between role and permission based authorization? ›

In short, permission-based access control defines permissions to each system's user. On the other hand, role-based access control specifies permissions to a set of roles of a system, roles assigned to each user. Both role and permission-based techniques are supported by other security methods.

What are the three permissions? ›

Files and directories can have three types of permissions: read, write, and execute: Someone with read permission may read the contents of a file, or list the contents of a directory. Someone with write permission may modify the contents of a file, including adding, changing, or deleting file contents.

What is the difference between access privileges and permissions? ›

Simply put, privileges are assigned permissions. When you assign a permission to a user, you are granting them a privilege. If you assign a user the permission to read a document, you are granting them the privilege to read that document.

How do you do role-based authorization? ›

For role-based authorization, the customer is responsible for providing the user ID, any optional attributes, and all mandatory user attributes necessary to define the user to Payment Feature Services. The customer must also define the roles that are assigned to the user.

What are the three types of role-based access RBAC controls in Microsoft Azure? ›

Azure broadly defines three different roles: Reader, Contributor, and Owner. These roles apply to Subscriptions, Resource Groups, and most all Resources on Azure.

What is the difference between role-based access control and discretionary access control? ›

What is DAC? Whereas RBAC, also known as non-discretionary access control, takes a more human-level approach to control access, Discretionary Access Control (DAC) uses ACLs to restrict access to resources, such as files and database tables, and define which privileges a user has for that resource.

What are the 4 major applications for enterprise applications? ›

There are four major enterprise applications:
  • Enterprise systems.
  • Supply chain management systems.
  • Customer relationship management systems.
  • Knowledge management systems.

What are the three types of enterprise application? ›

Major types of enterprise software. Currently, there are distinguished three main types of enterprise systems: customer relationships management (CRM), enterprise resource planning (ERP), and supply chain management (SCM).

What are the four enterprise applications? ›

The four main enterprise applications are enterprise systems, supply chain management systems, customer relationship management systems and knowledge management systems. a. Define what enterprise applications are and briefly explain each type as listed above.

How do I assign users to app roles in Azure? ›

Azure portal
  1. Sign in to the Azure portal.
  2. Select Azure Active Directory > Roles and administrators to see the list of all available roles.
  3. Find the role you need. ...
  4. Select the role name to open the role. ...
  5. Select Add assignments and then select the users you want to assign to this role. ...
  6. Select Add to assign the role.
Mar 9, 2023

Which Azure AD role grants all administrative permissions? ›

Categories of Azure AD roles

For example, User Administrator, Application Administrator, Groups Administrator all grant permissions to manage resources that live in Azure AD.

How do I assign a custom role in Intune? ›

To create a custom role
  1. In the Microsoft Intune admin center, choose Tenant administration > Roles > All roles > Create.
  2. On the Basics page, enter a name and description for the new role, then choose Next.
  3. On the Permissions page, choose the permissions you want to use with this role.
Apr 17, 2023

How do I authenticate an Azure AD application? ›

Configure client apps to access your App Service
  1. From the portal menu, select Azure Active Directory.
  2. From the left navigation, select App registrations > New registration.
  3. In the Register an application page, enter a Name for your app registration.
  4. Select Register.

How do I add apps to Azure AD for SSO? ›

Select Azure Active Directory in Azure Services, and then select Enterprise applications. Search for and select the application that you want to add linked SSO. Select Single sign-on and then select Linked. Enter the URL for the sign-in page of the application.

Can we create custom roles in Azure? ›

You can create custom roles using Azure portal, Azure PowerShell, Azure CLI, or the REST API. Create the custom role. The easiest way is to use the Azure portal. For steps on how to create a custom role using the Azure portal, see Create or update Azure custom roles using the Azure portal.

What is the difference between access token and access key? ›

Use API keys if you expect developers to build internal applications that don't need to access more than a single user's data. Use OAuth access tokens if you want users to easily provide authorization to applications without needing to share private data or dig through developer documentation.

What is the difference between consumer key and access token? ›

While the Consumer Keys give the API context about the developer App that is sending a request, the Access Tokens provide context about the Twitter user on behalf of whom the App is sending the request.

What is the difference between access token and SSH key? ›

While SSH keys can be read-only or read-write enabled, or scoped to specific repositories, personal access tokens do have an edge in terms of their finer-grained permissions model in comparison. This is likely why GitHub recommends tokens over SSH keys.

What three types of information make up an access token? ›

Access tokens contain the following information: The security identifier (SID) for the user's account. SIDs for the groups of which the user is a member. A logon SID that identifies the current logon session.

What is the purpose of the ID token? ›

What Is an ID Token? An ID token is an artifact that proves that the user has been authenticated. It was introduced by OpenID Connect (OIDC), an open standard for authentication used by many identity providers such as Google, Facebook, and, of course, Auth0.

Why do I need an access token? ›

Access tokens are used in token-based authentication to allow an application to access an API. The application receives an access token after a user successfully authenticates and authorizes access, then passes the access token as a credential when it calls the target API.

How do I access API with token? ›

Authorization
  1. Step 1: Create authorization request link.
  2. Step 2: Request user for authorization.
  3. Step 3: Exchange authorization code with access tokenpost.
  4. Step 4: Use access token for REST API requests.
  5. Step 5: Get new access token using refresh token.

How do I access API using access token? ›

Basic steps
  1. Obtain OAuth 2.0 credentials from the Google API Console. ...
  2. Obtain an access token from the Google Authorization Server. ...
  3. Examine scopes of access granted by the user. ...
  4. Send the access token to an API. ...
  5. Refresh the access token, if necessary.
Mar 6, 2023

How can I get token from authorization code? ›

How to get an access token with Authorization Code Grant
  1. Using code from Quickstart and modifying it to meet your app's needs. Quickstart generates a personalized project that contains an authorization code that you can use to implement Authorization Code Grant. ...
  2. Using refresh token methods from one of the SDKs.

How do I add roles to discord app? ›

How to add roles in Discord
  1. Click your server name in the upper-left corner of your server.
  2. Go to Server Settings > Roles.
  3. Click Create Role.
Mar 3, 2023

How do I add roles to Intune? ›

In the Microsoft Intune admin center, choose Tenant administration > Roles > All roles. On the Endpoint Manager roles - All roles blade, choose the built-in role you want to assign > Assignments > + Assign. On the Basics page, enter an Assignment name and optional Assignment description, and then choose Next.

How do I add an admin group to enterprise? ›

Step-by-Step Instructions to Secure Enterprise Admins in Active Directory
  1. Double-click Deny log on as a batch job and select Define these policy settings.
  2. Click Add User or Group and click Browse. Note. ...
  3. Type Enterprise Admins, click Check Names, and click OK.
  4. Click OK, and OK again.
Oct 8, 2021

How do I link Roles in Discord? ›

You can go to: Channel Settings > Permissions > Add Members or Roles > Select a Linked Role. If a channel is gated behind a Linked Role, members will need to meet all requirements before they're assigned the role to gain access to the Linked Role-gated channels.

What is the max number of Roles in Discord? ›

Yep, the max number of roles in a server is currently set to 250 total roles.

How do you duplicate a role in Discord? ›

Choose Home from the Table bar, click Settings, click Roles, then click the role you want to see. Locate the role you want to duplicate. To copy the role, click its Copy icon ( ). This icon is located in the rightmost column of the roles list.

How do I add a role to a Microsoft team? ›

Create a custom role

In the left navigation of the Microsoft Teams Rooms Pro Management portal, go to Settings > Roles. Select Create role. On the General settings page, under Role properties, enter a name for this role. Under Description, enter details about this role.

How do I assign apps to devices in Intune? ›

Assign an app
  1. Sign in to the Microsoft Intune admin center.
  2. Select Apps > All apps.
  3. In the Apps pane, select the app you want to assign.
  4. In the Manage section of the menu, select Properties.
  5. Scroll down to Properties and select Assignments.
  6. Select Add Group to open the Add group pane that is related to the app.
Apr 19, 2023

How do I add an app category to Intune? ›

To add a built-in app to your available apps in Microsoft Intune, do the following:
  1. Sign in to the Microsoft Intune admin center.
  2. Select Apps > All apps > Add.
  3. In the Select app type pane, under the available Other types, select Built-In app.
  4. Click Select.
Mar 6, 2023

What is the command to add to admin group? ›

Type net localgroup groupname username /add, where username is the name of the existing user you want to add and groupname is the name of the group you want to add them to. For example, if the group name is Accounting and the username is Bill, you would type net localgroup Accounting Bill /add.

How to add user to administrator group in Active Directory? ›

In the Active Directory Users and Computers program, right-click Users, point to New, and then click User. In the New Object - User dialog box, complete the description of the new user, and then click Next. Complete the password dialog box, and then click Next. Confirm the new user description, and then click Finish.

What's the difference between domain admin and enterprise admin? ›

The Enterprise Admins group is in the root domain of a forest. Domain Admins in this domain have full control of the root domain. Therefore, root Domain Admins can add and remove users from the Enterprise Admins group. As noted previously, valid reasons to use an Enterprise Admin account occur very rarely.

References

Top Articles
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 6101

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.