none or low, or no assessment is available, your backend will require a verified location check before it authorizes the action.
To require a particular store, workplace, or address, see Verify that the user is at a place or an address. If an action always requires the user to be in an allowed jurisdiction, as a wager does, see Verify location for compliance.
Complete example
This is the whole client flow for one withdrawal.api is your own backend client, which calls back on the main thread, and the show functions are your UI.
requireSession, transactions, and releaseWithdrawal are your own session middleware, store, and downstream call.
Prerequisites
- The device and network risk assessment must be enabled for your project. Contact your Radar account team.
- The Radar SDK and fraud plugin for your platform. See Fraud plugin setup.
Radar.revealRisk()requires iOS SDK 3.38.0 or later, Android SDK 3.35.0 or later,@radarlabs/plugin-fraud1.4.0 or later, or React Native SDK 4.36.0 or later. - A Test publishable key in your app, and the project’s JWT secret key on your backend only. See Choose the right API key.
- A stable, opaque ID for each account in your own system. Don’t use an email address or a phone number.
Create the transaction on your backend
For an action that your backend authorizes, such as a payment or a cashout, create the transaction before any Radar call, on an authenticated request, as thePOST /api/withdrawals route does. Generate the transaction ID on your backend so your app can’t choose it, and give the transaction a time limit that fits the action, 10 minutes in the example.
The transaction waits for a risk result (awaiting_risk), then either becomes authorized or waits for a location check (awaiting_location). The transition operation of your store must be a compare-and-set, so two concurrent requests can’t both authorize.
A login, a registration, or a redemption has no transaction. Send the risk token with that request instead, as the quickstart does.
Assess risk on the client
CallRadar.revealRisk() at the moment you want to assess, and send the signed token to your backend. The call doesn’t request location permission and doesn’t need a user ID, so it works before an account exists.
The token is optional in every SDK model. When the call fails or returns no token, still call your backend without one, so your backend records the risk as unknown.
Call Radar.setUserId() with your account ID after you authenticate the user, or as soon as your backend creates the account, and always before a verified location check. The userId is nullable. See Handle login, logout, and user switching.
Verify the token and read the result on your backend
The risk token is a JSON Web Token signed withHS256 and your project’s JWT secret key. Verify the signature and the expiry before you read any field, and accept HS256 only, as verifyRadarToken does.
The token carries no user ID. It is tied to the user and the transaction only because your backend received it on that user’s authenticated request and recorded its jti claim, which equals the assessment _id, once. At registration, accept the token with the registration request, and store the assessment ID and device.deviceId with the account you create.
Then read risk.level, which is one of none, low, medium, or high, and risk.reasons, which lists the signals found. For every field, see Read the result.
The /risk route has the only branch in this guide: none or low authorizes the action, and anything else requires the verified location check. Unknown risk, from a missing, invalid, expired, or reused token, takes the location path, because unknown risk isn’t low risk.
A risk level isn’t a probability of fraud, and which levels need the location check is your choice for each action. See Understand risk scores and decisions.
Read the fields for your scenario
Each scenario runs the same assessment at a different moment.
On
medium or high, an app typically asks for another authentication factor at login, asks for phone or document verification at registration, or holds a redemption for review.
A new device, several users on one device, or a shared network is context, not proof, so don’t block on one of these alone.
Compare device.deviceId values only with other values from risk assessments. Signals that depend on the user ID or on location, such as user.fraud.usersForThisDevice and user.fraud.mocked, come only from a verified location check. When an outcome is confirmed, record it as a label with the Labels API.
Request the verified location check
Ask for location permission only at this step. Tell the user why you need their location for this action, then request foreground location permission, as each tab of the complete example does. See Understand foreground and background location permissions. Granting permission isn’t verification. CallRadar.trackVerified() with the transaction ID from your backend as transactionId, and a reason from a small, fixed set, such as withdrawal. Radar returns both in the token and shows the reason in the Radar dashboard. Keep the same transactionId for every retry of the same transaction. On the web, pass skipVerifyApp: true, which runs the check in the browser without the Radar Verify companion app.
The check returns a signed geolocation token whether it passed or failed. Send it to your backend either way. When the check returns an error status, there is no token, and nothing was verified.
Validate the token and authorize once
The geolocation token is signed with the same key as the risk token. The/location route verifies its signature, algorithm, and expiry, and then checks, in order:
user.userIdis the session user, andtransactionIdis this transaction.- In production,
user.liveistrue. passedistrue. Otherwise it responds withfailureReasonsand leaves the transaction inawaiting_location.
authorized, with a compare-and-set, and call your downstream system. For the full procedure, see Validate a token. If your project uses encrypted responses, decrypt the token before you verify it.
Verify that the user is at a place or an address
passed covers the fraud checks and your allowed countries and states. It doesn’t say the user is at a particular store, workplace, or address. For an action tied to a location, such as a clock-in, an in-store redemption, or a delivery handoff, your backend reads passed first, then checks the place or the address in the verified payload. The required location comes from your own records, never from the request body.
- A place: Create one geofence for each store, workplace, or service location, each with an
externalIdthat matches the ID in your own system, such asstore-42. See Detect geofence events and place visits. A geofence doesn’t changepassed. Radar reports the geofences the user is in asuser.geofences. Location accuracy indoors varies, so a boundary drawn tightly around a building can exclude users who are inside it. - An address: Call
Radar.setExpectedAddress()with the address from your backend’s records before the check. Radar geocodes the address and returns the comparison inuser.expectedAddress:atAddressistruewhen the location is within the distance threshold of the address, 60 meters by default, andconfidenceishigh,medium,low, orunknown. When the user isn’t at the address, the token carries the warningaddress_not_expected, andpassedcan still betrue. See Expected address fields.
Address verification must be enabled for your project. Contact your Radar account team.
nil in Swift or null in Kotlin, or call Radar.fraud.setExpectedAddress() with no argument on web, when the workflow ends.
After your backend reads passed, these functions check each condition against the verified payload:
Node.js
passed set to true when nothing is wrong with the device or the region, so a backend that reads only passed would accept the action. Reject the action, and tell the user where they need to be.
Handle results and errors
No row authorizes the action on the client.Test the integration
Run these in the Test environment with a Test publishable key.- Passing case: Run the flow on a device with location permission granted. Confirm that your backend responds with
authorizedset totrue. Send the same passing token again, and confirm a409. - Failing case: Call the risk route with no token, and confirm that
locationRequiredistrue. Then block your test user with a block rule and run the check. Confirm a403withpassedset tofalseandfraud_blocked_user_idinfailureReasons.
Production checklist
- Your backend creates the transaction ID.
- Both tokens are verified on your backend with the JWT secret key and an explicit
HS256allowlist. - A missing, invalid, or expired risk token leads to the verified location check, not to direct authorization.
- The risk token’s
jtiis recorded once, and the geolocation token is bound to the authenticated user and to the transaction ID. - The transaction is authorized at most once, with an atomic state change, and never from a client-side value.
- Production builds use a Live publishable key, and your backend rejects tokens with
user.liveset tofalse.