/oauth/token
endpoint. This is useful for advanced integration use cases, such as:
subject_token_type
, which provides information about the user for the transaction, and an Action. In that Action, you can write custom code to decode and validate subject tokens passed to the /oauth/token
endpoint.
You can use Custom Token Exchange to authenticate users. For example, in an Action, you can apply the authorization logic for your use case and set the user for the transaction. Auth0 will then issue access, ID, and for the user.
allow_any_profile_of_type
attribute under token_exchange
to ["custom_authentication"]
:setUserById
operations.client_id
and client_secret
for later use when calling the /oauth/token
endpoint.
subject_token_type
and is associated with an Action that contains the code logic for that use case.
Custom Token Exchange requests sent to the /oauth/token
endpoint with a specific subject_token_type
value map to the corresponding Custom Token Profile and route to the associated Action for processing.
To create a Custom Token Exchange Profile, first create an Action for the profile.
/actions
endpoint:
actions[0].id
. You need the Action ID to create the Custom Token Exchange Profile.
/token-exchange-profiles
endpoint:
Parameter | Description |
---|---|
subject_token_type | Unique profile token type URI starting with https:// or urn The following namespaces are reserved and you can’t use them: * http://auth0.com * https://auth0.com * http://okta.com * https://okta.com * urn:ietf * urn:auth0 * urn:okta |
action_id | Action ID of Action associated with the Custom Token Profile. |
type | Should be set to custom_authentication . |
/token-exchange-profiles
endpoint.
To get all your Custom Token Exchange Profiles, make the following request. This endpoint supports checkpoint pagination in case you have several profiles.
name
or subject_token_type
of a Custom Token Exchange Profile, use the following PATCH request. You cannot modify the Action ID, although you can change the custom code it executes with the Actions editor:
event.transaction.protocol
value equal to oauth2-token-exchange
in your Post Login Action. Because the token exchange grant type is used by both the Custom Token Exchange and Native Social Login transactions, you can use the value of the subject_token_type
to distinguish between the two, where the subject_token_type
corresponds to one of your Custom Token Exchange Profiles.
api.multifactor.enable()
, api.authentication.challengeWith(),
or api.authentication.enrollWith()
is not yet supported for Custom Token Exchange and, within your Post-Login Action trigger, will result in the transaction failing with a non-recoverable error. Make sure you skip enabling MFA when event.transaction.protocol==oauth2-token-exchange
depending on the subject_token_type
value.MFA support will be added in next iterations of Custom Token Exchange EA.subject_token_type
. This will provide you with information about the user for the transaction. With this information, your code should also enforce the authorization policy needed for the transaction. Once you are sure the transaction can proceed, you can confirm it by setting the corresponding user. Auth0 will then issue access, ID, and refresh tokens for this user. You can think of this as a way to authenticate users.
Each Custom Token Exchange transaction generates a tenant event log. Successful transactions generate event logs of type secte
, while failed transactions generate event logs of type fecte
. Use these log types to help you understand any errors you may receive. Errors from the /oauth/token
endpoint reveal less details.
Parameter | Description |
---|---|
user_id | The user ID, such as auth0|55562040asf0aef . |
setUserByConnection()
. This method always fails for blocked users.
setUserByConnection()
for Auth0 database connections, Enterprise and Social connections, and Custom DBs with Import Users to Auth0 disabled.Parameter | Description | ||
---|---|---|---|
connection_name | The name of the connection where the user profile will be set. Limited to 512 characters. | ||
user_profile | An object containing the user profile attributes to be set. Limited to 24 properties. | ||
options | An object specifying update and creation behavior. `{updateBehavior: ‘replace' | 'none’,creationBehavior: ‘create_if_not_exists' | 'none’,} If the user exists, updateBahaviourdoes the following: * replace: the user attributes and the user_idfor the provided connection are replaced (existing user attributes that are not provided will be removed from the user. Partial updates are not supported). * none: if the user exists, the profile is not updated. If the user does not exist, it will be created with the provided profile attributes depending on creationBehaviorconfiguration. * If the user does not exist, creationBehaviordoes the following: + create_if_not_exists: create the user + none`: does not create the user and return with an error |
setUserByConnection()
method allows you to set profile attributes supported by the Update a User endpoint:
user_id
(required): user’s unique identifier for this connection/provider. It is typically the user ID provided by the external identity provider for the connection. This is the only required parameter when both creationBehaviour
and updateBehaviour
are set to none
.email
email_verified
. Defaults to false
.username
phone_number
phone_verified
. Defaults to false
.name
given_name
family_name
nickname
picture
setUserByConnection()
method fails for other strategies. Please contact Auth0 support to request adding support for other strategies.
Auth0 database connections:
creationBehavior
is set to create_if_not_exists
.
When creating users:
true
. To learn more, read Adding Username for Database Connections.phone_number
.email_verified
and phone_verified.
creationBehavior
to none
when you want to log the user in but don’t want to create the user if they do not already exist in the connection.Future iterations of Custom Token Exchange will make the email attribute optional dependent on the connection configuration.updateBehavior
is set to replace
.
The following attributes cannot be modified and Auth0 returns an error when trying to change its value:
email
username
phone_number
email_verified
phone_verified
setUserByConnection()
to update a user profile that already contains email
, username
, or phone_number
attributes, you must pass these attributes with the same value they already have. Otherwise, the method returns an error. Additionally, this action does not update the upstream Enterprise/Social IdP or the Custom DB, so make your updates match the latest version of the profile on the IdP/Custom DB if you want them to be in sync.updateBehavior
to none
when you want to log the user in but don’t want to change any profile attributes if they already exist in the connection.email_verified=false
. You can override this behavior by specifying verify_email=false
as a user profile attribute. It won’t be stored as part of the user profile.
setUserByConnection()
method does not allow you to set user or application metadata. Instead, you can use api.user.setAppMetadata
. To learn how to correctly use metadata, read How Metadata Works in User Profiles. For metadata best practices, read How to Manage User Metadata with the Post-login Trigger.
null
.
Parameters | Description |
---|---|
name | String. The name of the metadata property. |
value | String, object or array. The name of the metadata property. |
null
.
Parameters | Description |
---|---|
name | String. The name of the metadata property. |
value | String, object or array. The name of the metadata property. |
Parameter | Description |
---|---|
code | A string returned in the error property in the response. Two standard error codes can be used: * invalid_request : Returns a 400 status code * server_error : Returns 500 status code If you use your own error code, it returns a 400 status code. |
reason | A string returned in the error_description property in the response. |
400 Bad Request
error response with the error code invalid_request
.
When the maximum number of failed attempts is reached, Auth0 blocks traffic for a period of time for all Custom Token Exchange requests coming from that IP with a 429 Too Many Requests
error response with error code too_many_attempts
. To learn more read Attack Protection.
Use this method whenever you receive a Custom Token Exchange request with a subject token that is not properly signed/encrypted or expired, or under any circumstance that points to any non-legitimate usage such as in a spoofing or replay attack. This allows Auth0 to activate protection as per your configuration.
By default, Suspicious IP Throttling allows for 10 max attempts at a rate of 6 attempts/hour. To learn more, read Attack Protection.
Parameter | Description |
---|---|
reason | A string returned in the error_description property in the response |
jwks-uri
.
key
if it exists.
Returns a CacheWriteResult
object with type: "success"
if a value was removed from the cache. A failed operation returns type: "error"
. For errors, the returned object will have a code
property that indicates the nature of the failure.
Parameter | Description |
---|---|
key | String. The key of the record stored in the cache. |
key
, if it exists. If a record is found, the cached value can be found at the value
property of the returned object.
Returns a cache record if an item is found in the cache for the supplied key
. Cache records are objects with a value
property holding the cached value as well as an expires_at
property indicating the maximum expiry of the record in milliseconds since the Unix epoch.
Important: This cache is designed for short-lived, ephemeral data. Items may not be available in later transactions even if they are within their supplied lifetime.
Parameter | Description |
---|---|
key | String. The key of the record stored in the cache. |
ttl
or expires_at
values. If no lifetime is specified, a default lifetime of 15 minutes will be used. Lifetimes may not exceed the maximum duration listed at Actions Cache Limits.
Returns CacheWriteSuccess
if the values are stored successfully. Otherwise, you will receive CacheWriteError
.
Parameter | Description |
---|---|
key | String. The key of the record stored in the cache. |
value | String. The value of the record to be stored. |
options | Optional object. Options for adjusting cache behavior. |
options.expires_at | Optional number. The absolute expiry time in milliseconds since the unix epoch. While cached records may be evicted earlier, they will never remain beyond the supplied expires_at . Note: This value should not be supplied if a value was also provided for ttl . If both options are supplied, the earlier expiry of the two will be used. |
options.ttl | Optional number. The time-to-live value of this cache entry in milliseconds. While cached values may be evicted earlier, they will never remain beyond the supplied ttl . Note: This value should not be supplied if a value was also provided for expires_at. If both options are supplied, the earlier expiry of the two will be used. |
Property | Type | Example |
---|---|---|
client | ||
client_id | string | HOVc2PDFTH7eahimN4yNCo8mOtjfNjLV |
name | string | My Web App |
metadata | object | {“foo”: “bar” } |
tenant | ||
id | string | dev_1234 |
request | ||
geoip | object | { … geoip object} |
hostname | string | dev_1234.us.auth0.com |
ip | string | 123.42.42.34 |
user_agent | string | Mozilla/5.0 |
language | string | en |
body | object | { // raw req.body } |
method | string | POST |
transaction | ||
subject_token_type | string | urn://cic-migration-token |
subject_token | string | 41598922a1745f7af70 |
requested_scopes | string[] | [“openid”, “email”] |
resource_server | ||
id | string | http://acme-api/v1/profile |
POST
request to the /oauth/token
endpoint with the following parameters. Remember that:
subject_tokens
used with Custom Token Exchange can be any token format or type, as long as your Action code can interpret them.subject_token_type
maps to a specific Custom Token Exchange Profile and is associated with a specific Action that will be executed to control that transaction.Parameter | Description |
---|---|
grant_type | For Custom Token Exchange, use urn:ietf:params:oauth:grant-type:token-exchange . |
subject_token_type | The type of the subject token. For Custom Token Exchange, this can be any URI scoped under your own ownership, such as http://acme.com/legacy-token or urn:acme:legacy-token . The following namespaces are reserved and cannot be used: * http://auth0.com * https://auth0.com * http://okta.com * https://okta.com * urn:ietf * urn:auth0 * urn:okta |
subject_token | The subject token, which your action should validate and use to identify the user. |
client_id | The client ID of the application you are using for the Token Exchange. As for other grant types, you can also pass the client ID in the Authorization header using HTTP Basic Auth. |
client_secret | The client secret of the application you are using for the Token Exchange. As for other grant types, you can also pass the client secret in the Authorization header using HTTP Basic Auth. Other alternatives are also available as explained in Auth0 Authentication API reference docs. Note Custom Token Exchange can be used by public Applications. Make sure to read Attack Protection in that case. |
audience | The API identifier defined in Auth0. |
scope | The OAuth2 scope parameter. |
event.request.body
in the corresponding Action.
api.access.rejectInvalidSubjectToken
in your Action code whenever the received subject token does not pass strong validation.
Suspicious IP Throttling is activated by default for Auth0 tenants. To learn more about how to (de)activate and configure it, read Suspicious IP Throttling. When activated, the default settings for Custom Token Exchange will be applied:
PATCH
request to update the pre-custom-token-exchange
stage with the needed values. Note that the rate is the interval of time in milliseconds at which new attempts are granted.
api.authentication.challengeWith()
and api.multifactor.enable()
commands in Post Login actions are not yet supported for Custom Token Exchange and will result in the transaction failing with a non-recoverable error; similarly, transactions will also fail when MFA is configured as a tenant policysetUserByConnection()
operations/oauth/token
endpoint are rate limited at 10% of the global Authentication API rate limit for the applicable performance tier.
Performance Tier | Global Authentication API limit (RPS) | Custom Token Exchange limit (RPS) |
---|---|---|
Enterprise | 100 | 10 |
Private Cloud Basic (1x) | 100 | 10 |
Private Cloud Performance (5x) | 500 | 50 |
Private Cloud Performance (15x) | 1500 | 150 |
Private Cloud Performance (30x) | 3000 | 300 |
Private Cloud Performance (60x) | 6000 | 600 |
Private Cloud Performance (100x) | 10000 | 1000 |
api/v2/token-exchange-profiles
endpoints are also rate limited as follows:
Performance Tier | Custom Token Exchange limit (RPS) | Custom Token Exchange limit (RPM) |
---|---|---|
Enterprise | 20 | 200 |
Private Cloud Basic (1x) | 20 | 200 |
Private Cloud Performance (5x) | 100 | 300 |
Private Cloud Performance (15x) | 300 | 3000 |
Private Cloud Performance (30x) | 600 | 6000 |
Private Cloud Performance (60x) | 1200 | 12000 |
Private Cloud Performance (100x) | 2000 | 20000 |
invalid_request
error with a consent_required
error description when calling the /oauth/token
endpoint.
To resolve this issue, enable the Allow Skipping User Consent option for your API in the Auth0 Dashboard.