Generate device fingerprints
Generate device fingerprints and signals from the frontend and submit them as part of the authentication request.
Evaluate device recognition
Evaluate whether this is a recognized device using either the Stytch Device Fingerprinting Lookup response or the
user_device authentication response field, depending on which approach you choose in step 2, and Stytch User metadata.Conditionally show data
Conditionally show super-secret data within the application if either:
- The login request is from a known device, or
- The request is from a new device and the user completes Step-up MFA.
Store context and update devices
Store this context in Session custom claims via a claim called
authorized_for_secret_data for future reference throughout your application, and update the Known Devices list.Before you start
In order to complete this guide, you’ll need:- A Stytch project (either Consumer or B2B).
- If you don’t have one already, in the Dashboard, click on your existing project name in the top left corner of the Dashboard. Click Create Project, and then select B2B Authentication or Consumer Authentication.
- Access to Device Fingerprinting. If you don’t have access, you can request a trial.
- A basic authentication flow on which to add adaptive MFA.
- If you don’t have one set up already, you can use one of our example apps. The snippets in this guide will follow a recipe from our Next.js demo application (code here - look for “remembered device” files).
- This guide uses Stytch for authentication, but any backend authentication implementation can work.
- If you are using Stytch for authentication, this guide assumes you’re using a Consumer project. The same steps would apply to B2B projects as well if you don’t want to use Stytch’s built-in B2B MFA offerings.
Step-by-step walkthrough
Generating signals
The first step of this guide is step 1 and 2 of the Getting Started guide.Add the Stytch telemetry script to your login page:Add a method or event handler to call the async function When you call your backend authenticate endpoint, send the
GetTelemetryID(), which gathers signals from the device and resolves to a telemetry_id.telemetry_id along as well.In the snippet below from the example app flow, we’re using Email Magic Links as our authentication method, so the telemetry_id is generated and sent along in the request to authenticate the Magic Link token.Authentication and remembered device evaluation
- Stytch integrated approach
- Standalone DFP
The Stytch integrated approach assumes you are using Stytch for authentication and Device Fingerprinting and relies on specific Stytch features. If you are not using Stytch for auth, switch to the Standalone DFP tab.Your backend endpoint will:You can grab the
- Authenticate the Email Magic Link
token. - Get the Visitor ID from the
user_deviceresponse. - Compare this against the known devices list to determine whether this is a known device or not.
- Store the remembered device context in
session.custom_claimsfor reference downstream.
visitor_id from the user_device response field. Determine whether MFA is required based on whether the request is from a known device:- If known:
- Set
authorized_for_secret_data: truein the Session claims - Return super secret data already, or optionally return it elsewhere in your application, gated on
session.custom_claims.authorized_for_secret_data: true
- Set
- If not known:
- Store the pending Visitor ID in session custom claims for reference later on (to add to the known devices list in the case of a successful MFA flow)
- Set
authorized_for_secret_data: falsein the Session claims - Let the frontend know that MFA is required
user_device in the response could be null if the fingerprint lookup failed for any reason, such as an invalid telemetry_id. If the user_device is null, you should fail closed and always require MFA for security reasons.Conditional access and MFA enforcement
Trusted Device → Grant AccessUntrusted Device → Prompt MFANow your application enters the Conditional Access and MFA Enforcement step: Trusted devices receive access to the protected data; unrecognized devices must complete MFA before access is granted.Below are two different approaches - the first uses a dedicated backend endpoint, the other uses React’s Use this known device data to determine frontend behavior; for example, the React component in our example app looks like:
getServerSideProps:- Backend
- React
In our integrated example application recipe, we implement that logic in a backend endpoint called
/api/known_devices_integrated.What’s next?
Want to try Stytch Device Fingerprinting?
Find out why Stytch’s device intelligence is trusted by Calendly, Replit, and many more.