Enabling identity tokens
To enable identity tokens for your application:- Navigate to your application dashboard’s User management > Authentication > Advanced section
- Toggle on Return user data in an identity token
- Make sure you’re using the latest version of the Privy SDK
Token format
Privy identity tokens are JSON Web Tokens (JWT), signed with the ES256 algorithm. These JWTs include the following claims:Retrieving identity tokens
Once you’ve enabled identity tokens, Privy will automatically include the identity token as a cookie on every request from your frontend to your server.For setups where you cannot use cookies, you can retrieve the identity token using the
useIdentityToken hook or the getIdentityToken method:Reading identity tokens on your server
On your server, you can retrieve the identity token from incoming requests and use it to identify the user.Accessing custom metadata
Privy allows you to set custom metadata for a user via backend API requests. This metadata is available in thecustom_metadata claim of the identity token.
Here’s how to parse and access it:
Refreshing the identity token
A new identity token is automatically issued when a user:- Authenticates into the application
- Links or unlinks an account
- Refreshes their application page
- Calls
getAccessTokenwhen the access token is expired
To programmatically refresh the identity token, call
refreshUser from the useUser hook:Verifying the identity token
When your server receives a request with an identity token, you should verify the token’s signature to authenticate the user. The preferred way is to use thegetUser method from the @privy-io/node SDK, which handles verification and parsing:
The
verifyAuthToken method will not work on identity tokens, as it is only used to verify Privy
access tokens. Always use get({id_token}) when working with identity tokens.get, you can use JWT libraries like jose:
Security considerations
For optimal security when working with identity tokens:- Always verify the token signature before trusting any claims
- Check the expiration time (
expclaim) to ensure the token is still valid - Set a base domain for your application to enable HttpOnly cookies for the identity token
- Use HTTPS for all communication between your frontend and backend
- Do not store sensitive information in custom metadata, as it will be included in the identity token
Read more about Privy’s tokens and their security in our security guide.

