It’s no secret that I use Auth0 for nearly all of my projects. Generally, I’ll just use the base offering, take the token it gives me, and move on. However, this time, I wanted to actually try to more fully utilize some of the features Auth0 provides. I didn’t want to keep having to do a back-and-forth “sign up” flow, where I give my server a token, the server validates it, then checks if I’ve signed up before. If not, it would send a message back saying “hey, you need a username” and that dance would continue until the user is fully registered.

This time, I’m going to use the username provided by Auth0, and show you how to add it to the id_token payload so you don’t have to make an extra API call to get it.

It’s pretty simple. In your Auth0 tenant, head over to Rules. Hit the big “Create Rule” button, and select the blank template.

You have to namespace your claim to add it to the id_token unfortunately, but on the positive side the namespace is never “called” (no http requests, or anything of the sort), so it can be whatever you want. Using your project name as a namespace probably isn’t a bad idea. You can find more about Auth0 rules here.

Now, when you get a token from Auth0, you can head over to jwt.io and paste it in - you’ll see the payload has changed slightly: