Configure and Implement Multi-Resource Refresh Token
Learn how to configure and implement multi-resource refresh token
Multi-Resource Refresh Token is currently in Early Access. By using this feature, you agree to the applicable Free Trial terms in Okta’s Master Subscription Agreement. To learn more about Auth0’s product release cycle, read Product Release Stages.
To use Multi-Resource (MRRT), configure your application’s refresh token policies using the Auth0 Management API. These policies will specify which API and scopes the application is allowed to request during a refresh token exchange.You can define MRRT policies in the refresh_token.policies property of the application.
Property
Type
Description
audience
string
The Auth0 API identifier of the application that will have access to using the refresh token.
scope
Array of strings
The list of scopes allowed when requesting an access token for the specified audience. The scope must be equal to or narrower than the scopes defined on the API.
The audience and scope properties must correspond to an existing application in your tenant, otherwise the refresh token exchange will silently ignore them.
For existing applications, make a PATCH call to the Update a Client endpoint. To create a new application, make a POST call to the Create a Client endpoint:Sample response:
Once you configure your application’s refresh token with MRRT policies, you can start to exchange a single refresh token for across multiple APIs.
To facilitate this, your application needs to initiate a login flow using either the Authorization Code Flow or the Resource Owner Password Grant.
Step 2: Exchange the refresh token for a different API
Once the refresh token is issued, you can request access tokens for any API and scopes defined in both the initial authentication and the MRRT policy. For example: To learn more, read Use Refresh tokens.If you are using the Auth0 Swift SDK, you can exchange the refresh token using the following code:
コピー
credentialsManager.apiCredentials(forAudience: "https://example.com/me", scope: "create:me:authentication_methods") { result in switch result { case .success(let apiCredentials): print("Obtained API credentials: \(apiCredentials)") case .failure(let error): print("Failed with: \(error)") }}
To learn more, read Auth0 Swift SDK.If you are using the Auth0 Android SDK, you can exchange the refresh token using the following code:
Using MRRT with Actions allows you to configure dynamic decision-making based on the application’s MRRT policies. To facilitate this, post-login Actions features the event.client.refresh_token.policies object that provides relevant information including and scope.You can use the event.client.refresh_token.policies object to evaluate the application’s audience and scope, when issuing or exchanging a refresh token, and to ensure precise control over API access and scopes.
コピー
exports.onExecutePostLogin = async (event, api) => { // return the list of allowed APIs in the client const allowedAPIsInTheClient = event.client.refresh_token?.policies; if(allowedAPIsInTheClient?.some(policy => policy?.audience?.includes('https://myapi'))){ // custom logic }};
MRRT acts as an extension of the original authentication, not a replacement. When exchanging a refresh token, Auth0 evaluates the exchange request using the following logic:
If the audience parameter is omitted , Auth0 returns an access token with the original audience and any of its additional scopes configured in the MRRT policy.
If a new audience parameter is specified , Auth0 verifies that the audience is included in the MRRT policy and returns an access token for the new audience with its configured scopes.
If the scope parameter is omitted , Auth0 combines all allowed scopes from the original request and the MRRT policy.
If a new scope parameter is specified , Auth0 validates the requested scopes and returns an access token with the scopes included in the MRTT policy. Invalid or unauthorized scopes requested are silently ignored.
If the audience parameter is the same as from the original request , Auth0 applies the MRRT policy and returns an access token for the audience with all MRRT configured scopes and original authentication scopes.
MRRT allows you to extend user access to new APIs without issuing new refresh tokens or requiring user login again.