I have tried many ways of getting a JWT with my custom claims set on it from app_metadata, but without success.
I am developing a backend-only api (there will be a frontend build later) with authentication via Auth0. I am using the userId stored in the JWT to connect Auth0 users to data in my own application database. I need to also access other data which I’ve stored in app_metadata and which I set as a custom claim in a Post Login action. My problem is that I cannot get a JWT which was was created using my action. (I need the raw JWT to test my api) Either I get my JWT using /oath/token and my Post Login action is not triggered, or I login with a test frontend and I can’t get access to the raw JWT.
What I’ve tried:
Using postman/browser I’m able to visit this endpoint in my browser: https://{{auth0_domain}}/authorize?response_type=code&client_id={{auth0_client_id}}&redirect_uri={{redirect_uri}}&audience={{audience}}
This gives me a code which I can exchange for a JWT by posting to https://{{auth0_domain}}/oauth/token, but it this does not go through my post login action (so it is missing the custom claims).
I’ve also tried logging in to a test frontend app and I can see that the claims are being set correctly, but I’m not able to get access to my JWT. I know it is set in my browser, but it seems like I’m not supposed to be able to access it.
I see that you are on the right track, as you are already calling the /authorize endpoint to get a code to exchange it for an access token to the /oauth/token endpoint.
Everything looks correct. However, since you have not been getting the custom claims, I would recommend reviewing your Action script and using console.log() statements to debug and see what is preventing the claims from being appended.
As I tried to explain in my original post, my action does seem to be working. My problem is that the post login action never even gets run if you are logging in by calling the /authorize endpoint to get a code to exchange for an access token from the /oauth/token endpoint.
You could use the Real-time Webtask Logs Extension to monitor the action script’s execution in a login flow. Could you give it a try and let me know what happens?