Auth0 has recently introduced its new Actions platform as a successor of the Rules and Hooks platform:
I wanted to implement the most simple way of issuing access tokens for a Daml ledger, and found the following:
In Auth0, we can attach arbitrary data to a user profile, so I attached the whole set of custom claims a Daml ledger requires in an access token:
This can be set by an admin, who creates the user in Auth0, through the Auth0 management API, in parallel with allocating the ledger party for the user.
Based on this set of data, we can add the custom claims to the access token with a simple custom action in Auth0:
After creating the custom action, we can include the action into the login flow.
After this, if a Daml application redirects its user to the Auth0 authorize endpoint with this URL:
https://<your-auth0-tenant-domain>.com/authorize?response_type=token&audience=https%3A%2F%2Fdaml.com%2Fledger-api&client_id=<your-client-id>&redirect_uri=http://<your-daml-app-url>/auth/cb&state=12345
and the user authenticates on the Auth0 Universal Login screen, the user gets redirected to the Daml application with the access token in the URL hash fragment:
http://<your-daml-app-url>/auth/cb#access_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik5rVkNRVVpFUmpSRk1qY3hOa1U1UmpaQ1JVSXdNa001UVVRNU9USXdPRFZCTXpkRE0wUkNOdyJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsiYWN0QXMiOlsiYWxpY2UiXSwiYWRtaW4iOmZhbHNlLCJhcHBsaWNhdGlvbklkIjpudWxsLCJsZWRnZXJJZCI6ImFhYWFhYWFhYS1iYmJiLWNjY2MtZGRkZC1lZWVlZWVlZWVlZWUiLCJwYXJ0aWNpcGFudElkIjpudWxsLCJyZWFkQXMiOlsiYm9iIl19LCJpc3MiOiJodHRwczovL2Rldi1ucW4wd2Vqay5ldS5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NjA4ZmVmN2RiMTVjM2YwMDY5MGZmY2FjIiwiYXVkIjoiaHR0cHM6Ly9kYW1sLmNvbS9sZWRnZXItYXBpIiwiaWF0IjoxNjIxNDQ1MDI3LCJleHAiOjE2MjE0NTIyMjcsImF6cCI6IkJzcWp3c0pqdHd1UkZuR0EwcVJEWlRjbEVsR1Y3a1BLIiwic2NvcGUiOiIifQ.VzfgBgYGqhQsyNAxpv0UmNSTbSl5t7Lsw1ctHVInmZ4CfBJ15GVVfD97Ajx3snefllxaMYXBR8IfARcekaQVnlwvqkJESVh7Lw3wIWoIdDstrx9kass8s5wBp8Ge6BtEN44ozaizj5m8EQv_m_H7pqP1idM2zvitzQ6GvtYbaaX7NBwhw7cy0SdZeGZNdic-LoQNV3l8Aa_iH6rvipmc1bfBuJcpAnGjOw2ID8wP5jHIlFbUbUBOpWWR3EYF_lvj_tXa0yNxP2oJoTsY_W2pfT6HNf_qnuVC0uxWfM9GIyuCsqVAN4ZlRysIdfOVxbENlqSb5v3tk9D8dFwqL-xbkw&expires_in=7200&token_type=Bearer&state=12345
We can check that the access token indeed contains the custom claims we have set in the user profile:
Of course, putting the JWT token into the response URL is not the safest way of access token handling. You have safer options by choosing an alternative authorization flow.
See the details of the Implicit Grant flow which is used here: SPA + API: Solution Overview