Search code examples
javafirebasefirebase-authenticationjwt

Firebase "getIdToken(true)" in Java Backend


I'm posting in reference to this question. I have this exact same issue and I haven't found a way around it.
We have a custom token created with additional claims, and when we need to perform a change on these claims the user needs to sign out and then sign in again for the claims to be impacted. The token does not change as long as the session is alive. How can we go about this?

I tried the exact same thing as mentioned in the referenced post, with the same results. I also tried setting the claims as null manually, to then update them with the correct value, without results

Thanks in advance!


Solution

  • A Firebase ID token is immutable, and most JWTs in general are. Once it's been minted, you cannot change it.

    If you want to change claims in a user's profile, you'll need to mint a new token with those claims. That new token can then be used instead of the previous token, even though that previous token will also still be valid until its exp value.

    If you've added claims to a user account on the server, you can call getIdToken(true) on the client to force it to get a fresh token from the server with the latest claims.