Auth0 provides two ways to implement role-based access control (RBAC), which you can use in place of or in combination with your API’s own internal access control system:The Authorization Core feature set matches the functionality of the Authorization Extension, improves performance and scalability, and provides a more flexible RBAC system than the Authorization Extension.Currently, both implement the key features of RBAC and allow you to restrict the custom scopes defined for an API to those that have been assigned to the user as permissions.
- Add custom claims to the issued token.
- Determine the user’s group membership, roles, and permissions.
- Store the user’s groups, roles, and permissions info as part of the
app_metadata
. - Add the user’s groups, roles, and permissions to the outgoing token (which can be requested via the
openid groups permissions roles
scope).
Add custom claims to the issued token
To add custom claims to your tokens, you can do so by creating an additional rule that allows the Authorization Extension to do so. Custom claims can be namespaced or non-namespaced. To learn more, read Create Custom Claims. You should limit the number of claims you add to the token./authorize
endpoint or configuring Lock, you’ll need to specify the information you want in the scope
by indicating groups
, permissions
and/or roles
.
Control app access
You can also write rules that are executed after the Authorization Extension rule to do things like control access to your application. One method of doing this is to specify the roles that are required for each application using the application metadata. For more details, review Manage Metadata with Rules.Set app metadata required roles
You can set the app’s metadata with roles, which are groups of permissions that you group together to create a specific set of functionality. You can think of this step as “tagging” the app so that the rules you set up know which app to act on.- To set the
context.clientMetadata
field withrequired_roles
, select the application you want to work at Auth0 Dashboard > Applications > Applications. This brings you to the application’s Settings. Scroll down, and select Show Advanced Settings at the bottom of the page. - Under Application Metadata add an item setting the Key to
required_roles
and in Value field list your roles in comma separated style. Select + Add to add the field. - When finished, select Save Changes. Now, when you log in from this application, in
context.clientMetadata
, you will have therequired_roles
with the roles value string you entered.
Create rule enforcing app roles
Now that each app has a role associated with it, you can create the rule executes with this piece of app information in context.- Before creating this rule, enable Roles under the Token Contents and publish the Authorization Extension rule.
- Add this rule and make sure it is listed after the generated “auth0-authorization-extension” rule.
-
After setting
required_roles
, create a new rule with the following body: