Use Actions to extend Auth0:
- To learn more about Actions, read Understand How Auth0 Actions Work.
- To migrate, read Migrate from Hooks to Actions.
Prerequisites
Before beginning this tutorial, you must:- 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
- Create Hook: Create a hook that will customize your token.
- Test Hook: Test your new hook by running a Client Credentials Flow and decoding the access token.
Create a Hook
In this example, you will:- add an arbitrary claim (
https://foo.com/claim) to the Access Token - add an extra permission to your configured API
Client Credentials Exchange, and add the following code in the editor:
Test your Hook
To test the hook you just created you need to run a Client Credentials exchange, get the , decode it, and review its contents.Get token
To get a token, make aPOST call to the Client Credentials Flow endpoint. Be sure to replace CLIENT_ID, CLIENT_SECRET, and API_IDENTIFIER placeholder values with your application’s , your application’s , and your API’s Identifier, respectively. You can find the Client ID and Client Secret in your Application settings and the API Identifier in your API settings.
A successful response will include:
- an
access_token, - its expiration time in seconds (
expires_in), - the token’s type set as
Bearer(token_type), and - an
extrapermission (scope) (which was added by your Hook)
Decode token
The easiest way to decode the access token and review its contents is to use the JWT.io Debugger. Copy your access token and paste it into the editor. The is decoded automatically and its contents are displayed. Note that the last two items of the Payload have both been set by your hook:"scope": "extra""https://foo.com/claim": "bar"