Validate a token
Your backend verifies the geolocation token and readspassed from it. If passed is false, your backend rejects the action. The result your app receives is for your UI. A value such as passed that arrives outside a verified token isn’t proof. Verify the signed token on your backend before a protected action.
Decoding a token isn’t validating it. Decoding only reads the payload, and anyone can produce a payload that decodes. Validation means verifying the signature with your secret key and then checking the claims in Validation steps.
The signing key is your project’s JWT secret key, described in Envelope. The same key signs and verifies, so it belongs only on your backend. Store it in your secret manager and load it from an environment variable. Don’t ship it in a mobile app, a web bundle, or a repository.
Validation steps
Run every step, in this order, for every token. Reject the request at the first step that fails.
A JWT library does steps 2 to 4 and nothing else. It knows nothing about your users, products, or actions, so steps 5 to 9 are code you write. A token that passes steps 2 to 4 is authentic. Steps 5 to 8 confirm it belongs to this request, and step 9 reads the result.
Notes on specific steps:
- Trusted key selection: Select the key from your own configuration for the project and environment that the request belongs to. Don’t select a key based on anything inside the token.
- Clock skew: If you allow a tolerance on
exp, keep it to a few seconds. - Product result:
passedis the result for the product inproduct. When your project returns aproductsobject, it holds onepassedvalue per configured product, and you can readproducts.<name>.passedfor the product of the action. - Replay: Radar doesn’t track whether a token has already been presented. A token stays valid until
exp. If an action must be performed only once, pass atransactionIdto the check, and have your backend mark that identifier as used. - Unknown fields: The payload can gain fields. Ignore fields you don’t use instead of rejecting the token.
Example: Node.js
This example uses thejose library, which verifies the signature, the algorithm allowlist, and exp. The function returns the verified payload, and throws when the token is invalid, expired, or doesn’t belong to the request.
Node.js
passed:
Node.js
Example: Python
This example uses PyJWT, which verifies the signature, the algorithm allowlist, andexp. The function returns the verified payload, and raises jwt.InvalidTokenError when the token is invalid, expired, or doesn’t belong to the request.
Python
passed from the returned payload. If it isn’t True, reject the action and return payload["failureReasons"] so that your app can explain why.
Act on the validation result
When your backend can’t validate a token, including when your own validation code throws, reject the action.
Reuse a verified result for a session
You can require a token on every restricted request, or verify a token once and remember its result. If you remember it, store the verified values on the server, keyed by your session:passed is true, and the current time is before expiresAt. Take expiresAt from the token’s exp claim, and keep _id from the token as locationCheckId so that support staff can find the check in the dashboard. Replace the stored result each time your backend verifies a later token for the same session, including one with passed set to false.
For withdrawals, redemptions, and other single-use actions, require a token on the request itself, tied to the action with transactionId.
Change the secret key
The token header has no key identifier, so your backend can’t pick a key per token. If your project’s JWT secret key is replaced, tokens signed with the previous key stop verifying once your backend loads the new key. To avoid rejecting tokens during the change, configure both keys for a short overlap, try the current key first, then the previous key, and remove the previous key after the longest token lifetime has elapsed.Negative tests
Cover each of these in your backend tests. Sign test tokens with a test-only secret. To build the wrong-user and expired fixtures, see Fixtures for rejection tests.Encrypted responses
Encrypted responses must be enabled for your project. Contact your Radar account team.
token is a JWT signed with a secret key that Radar and your backend share. As an alternative, Radar can return token as a JSON Web Encryption (JWE) token. Radar signs the response with its own private key, then encrypts it with a public key that you upload, so only your backend can decrypt the response.
Encrypted responses are available for Radar.trackVerified() and Radar.revealRisk(). With them, Radar returns only token, passed, expiresAt, and expiresIn to the client. Everything else, including user, events, and failureReasons for location checks and risk, network, and device for risk assessments, is only in the encrypted token. Send the token to your backend to read it.
Create and upload a key
Create an EC P-256 key pair, and convert the public key to a JSON Web Key (JWK). The private key must never leave your backend.- Under Response encryption keys on the Settings page of the Radar dashboard, select Add.
- Choose the Live or Test environment, then upload your public JWK file or paste its contents.
- After your backend has the private key, open the menu on the key’s row and select Activate. A new key is disabled until you activate it.
d field, the dashboard shows the error Enter a public P-256 JWK without private key material. Only one key is active for each environment, and Live and Test keys are separate. You need the owner role to add, activate, or delete keys.
Decrypt and verify a token
On your backend, decrypt the token with your private key, then verify Radar’s signature on the decrypted JWT. Radar encrypts withECDH-ES and A256GCM, and signs with ES256. Radar’s public signing keys are published at https://api.radar.io/.well-known/jwks.json.
Node.js
After you verify the token, apply the same user, product, and freshness checks as for a default token. See Validation steps.
Rotate a key
Add a new key, deploy its private key to your backend, then activate the new key. Activating a key disables the previous key for that environment. Keep the previous private key until the tokens encrypted with it expire. Thekid header of each token is the Key ID of the key that encrypted it, so your backend can choose the matching private key. You can delete a key after it’s disabled.
Envelope
The token is a JSON Web Token (JWT) in JWS compact serialization. It has three base64url segments separated by periods:
Reject any token whose header
alg isn’t HS256. This section describes the default token. An encrypted response is a JWE token instead.
Registered claims
The JWT library you use reads these claims. Both are in seconds since the Unix epoch.Payload fields
Field names are case-sensitive. The payload can contain fields that aren’t listed here, and new fields can be added, so ignore fields you don’t use.Top-level fields
User fields
Fraud fields
Individual flags explain a result. The decision field is
passed.
Country and state fields
user.country and user.state share these fields.
user.state also has:
Expected address fields
Identity, product, and freshness
Check these four things in the verified payload before you act onpassed.
- Identity:
user.userIdis the value your client set withRadar.setUserId(). Radar doesn’t authenticate your users, so the token proves which user ID the check ran for, and your backend proves who is making the request. Compare the two on every request. - Product:
passedapplies to the product named inproduct. A token issued for one product doesn’t establish eligibility for another. If your project returnsproducts, each entry holds the jurisdiction result for that product from the same check. - Environment:
user.livetells you whether the check ran in the Live or Test environment. In production, accept only tokens withuser.liveset totrue. - Transaction:
transactionIdis returned exactly as you passed it. Radar doesn’t enforce single use. Your backend compares it to the action it is authorizing and records that it has been used.
Expiry
Each token has its own lifetime. Radar sets it per check based on your product and jurisdiction configuration and the distance to the border, so tokens issued close to a border expire sooner. The default lifetime is 20 minutes, anexpiresIn of 1200.
expis the authoritative expiry for your backend. JWT libraries enforce it.expiresAtis the expiry as an ISO 8601 datetime, for scheduling and display.expiresInis the lifetime in seconds, measured fromiat. Add it to the time you received the response, not to the current time when you read it later.
- On the client, start the next check shortly before the expiry so that a valid token is always available.
- When the app returns to the foreground, or a page becomes visible again, compare the current time to
expiresAtbefore you reuse a stored token. - Run a new check when the user changes product, when the signed-in user changes, and before an action you bind with a
transactionId.
Read the client result
The client returns a status and, on success, a token object.
Send the token to your backend with the protected request. Your backend verifies the token and reads
passed itself, so a passed value changed on the device has no effect.
Handle a failed check
A failed check is a successful request withpassed set to false and at least one entry in failureReasons. It means Radar reached a conclusion about the user or device.
- Show a message that helps the user fix the cause, such as moving to an allowed area or disconnecting a VPN. For each reason, see Failure and warning reasons.
- Let the user run a new check after they change something. Don’t loop automatically on a failed check.
- If failure reason messages are enabled for your project, the payload includes
user.failureReasonMessages, keyed by failure reason, with amessageto display and aretryflag. This is account-specific configuration.
warningReasons lists signals that Radar reports without failing the check. A check with warnings can still have passed set to true. Warnings are in the token payload that your backend reads.
Handle a technical error
A technical error means the check didn’t complete. The client returns a status other than success, and no token. It says nothing about the user’s eligibility, so don’t treat it as a failed check, and don’t treat it as a pass.
Until a new check succeeds and your backend validates its token, keep the protected action blocked.
Failure and warning reasons
Some sensitive or proprietary failure reasons aren’t documented here. Contact your Radar account team for more information. Handle values you don’t recognize with a general message.
passed is false, failureReasons lists why. Depending on your compliance requirements and fraud preferences, some failure reasons can be downgraded to warning reasons. warningReasons lists those signals without failing the check, so a token with warnings can have passed set to true.
Jurisdiction reasons
Fraud reasons
Device or app compromise
Location accuracy
Location jumping
Location mocking or spoofing
Proxy or VPN usage
Screen sharing or remote desktop
Block reasons
Example payloads
These are decoded payloads after signature verification. They are synthetic, and they omit optional fields that your project can return. The envelope around each one is described in Envelope.Passed check
The user passed all jurisdiction and fraud checks for thesportsbook product.
Failed eligibility check
The request succeeded and the token is authentic. The user is in a state that isn’t allowed, sopassed is false. No fraud check failed.
Passed check with a warning
The check passed, and Radar reported that the user isn’t at the expected address.passed stays true. Your application decides what the warning means for the action.
Fixtures for rejection tests
Two cases that your backend must reject use an authentic token with a passing payload, so they need no separate payload shape:
Sign test fixtures with a test-only secret, never with your project’s JWT secret key.