I am trying to use the authorization code flow with an app authorized with the management API. For testing purposes I am doing this using curl and my web browser.
Firsly, I visit the browser using the following URL constructed:
https://<tenant domain>/authorize?audience=https%3A//<tenant domain>/api/v2/&response_type=code&client_id=<client id>&redirect_uri=http%3A//localhost%3A31313
I authorize the application, and get a redirect back to the following url:
http://localhost:31313/?code=<code>
All as expected so far! I then perform the token exchange via curl from the command line:
$ curl -X POST "https://<tenant domain>/oauth/token" --data-urlencode "client_id=<client ID>" --data-urlencode "client_secret=<client secret>" --data-urlencode "grant_type=authorization_code" --data-urlencode "code=<code copied from the above url>" --data-urlencode "redirect_uri=http://localhost:31313" -i
HTTP/2 200
date: Thu, 30 Jan 2025 12:27:37 GMT
content-type: application/json
--- other headers ---
{"access_token":"<access_token>","expires_in":86400,"token_type":"Bearer"}
As you can see everything works just fine! However, the access token does not work when trying to use with the management API:
$ curl "https://<tenant domain>/api/v2/users/<my user id>" -H 'Authorization: Bearer <access token>' -i
HTTP/2 401
date: Thu, 30 Jan 2025 12:43:18 GMT
--- other headers ---
{"statusCode":401,"error":"Unauthorized","message":"Invalid token","attributes":{"error":"Invalid token"}}
Inspecting the token up close I noticed that the middle part of the jwt actually seems to contain invalid json; i.e. if I take the middle bit and base64 decode it I get the following json:
$ echo '<access token>' | awk -F '.' '{print $2}' | base64 -d
{"<custom claim from a rule>":"<redacted>","<custom claim from a rule>":"<redacted>","iss":"https://<auth0 tenant domain>/","sub":"<my user ID>","aud":"https://<auth0 tenant domain>/api/v2/","iat":1738239941,"exp":1738326341,"azp":"<client id>
As you can see it seems correct, except at the end it does not have the closing quote and the closing curly brace. When pasting the full token into jwt.io
it says that the signature can be verified, so it doesn’t seem like I’m truncating the access token in any way. What next steps can I take to diagnose this issue further?
Thanks in advance!