This tutorial will help you call your API from a machine-to-machine (M2M) application using the Client Credentials Flow. To learn how the flow works and why you should use it, read Client Credentials Flow.
Prerequisites
Before beginning this tutorial:- Register your API with Auth0
-
Register the M2M Application with Auth0.
- Select an Application Type of Machine to Machine Applications.
- Choose your previously-registered API.
- Authorize the M2M Application to call your API.
Steps
- Request tokens: From the authorized application, request an access token for your API.
- Call API: Use the retrieved access token to call your API.
Request tokens
To access your API, you must request an access token for it. To do so, you will need toPOST
to the token URL.
Example POST to token URL
Parameters
Parameter Name | Description |
---|---|
grant_type | Set this to “client_credentials”. |
client_id | Your application’s Client ID. You can find this value on the application’s settings tab. |
client_secret | Your application’s Client Secret. You can find this value on the application’s settings tab. To learn more about available application authentication methods, read Application Credentials. |
audience | The audience for the token, which is your API. You can find this in the Identifier field on your API’s settings tab. |
organization | Optional. The organization name or identifier you want the request to be associated with. To learn more, read Machine-to-Machine Access for Organizations. |
Response
If all goes well, you’ll receive anHTTP 200
response with a payload containing access_token
, token_type
, and expires_in
values:
Validate your tokens before saving them. To learn how, read Validate ID Tokens and Validate Access Tokens.