Learn how Authsignal rules enable risk-based authentication and how to implement them in your app.
Authsignal’s rules engine transforms static authentication flows into intelligent, risk-based security systems. Rules determine when and how to challenge users based on contextual factors.
Rules are conditional statements that evaluate the context of each action to make intelligent security decisions. While actions define what users are doing, rules determine when and how to challenge them based on risk factors, device characteristics, user behavior, and custom business data.
When you create a rule in Authsignal, you’re defining the logic that determines when additional security measures are required. Here’s what a rule contains:
When a rule’s conditions are met, it can override the action’s default outcome with any of the four available action outcomes (ALLOW, CHALLENGE, REVIEW, or BLOCK). This allows you to apply outcomes dynamically based on risk assessment rather than using a static default.
Rules work seamlessly with your existing action tracking. When you track an action, Authsignal evaluates all applicable rules and returns the appropriate outcome.
// Track an action - rules are evaluated automaticallyconst result = await authsignal.track({ userId: "0272c312-e181-4cad-a494-43647b503a0a", action: "withdraw-funds", attributes: { deviceId: "device-abc", ipAddress: "203.0.113.1", userAgent: "Mozilla/5.0..." }});// Handle the result based on rule evaluationif (result.state === "CHALLENGE_REQUIRED") { // Rule determined a challenge is needed return { token: result.token // For custom UI with SDKs };} else if (result.state === "ALLOW") { // Rule determined user is trusted return { success: true };} else if (result.state === "REVIEW") { // Rule determined manual review is needed return { status: "under_review", message: "Your request is being reviewed" };} else if (result.state === "BLOCK") { // Rule determined this is high-risk return { error: "This action has been blocked for security reasons" };}
// Track an action - rules are evaluated automaticallyconst result = await authsignal.track({ userId: "0272c312-e181-4cad-a494-43647b503a0a", action: "withdraw-funds", attributes: { deviceId: "device-abc", ipAddress: "203.0.113.1", userAgent: "Mozilla/5.0..." }});// Handle the result based on rule evaluationif (result.state === "CHALLENGE_REQUIRED") { // Rule determined a challenge is needed return { token: result.token // For custom UI with SDKs };} else if (result.state === "ALLOW") { // Rule determined user is trusted return { success: true };} else if (result.state === "REVIEW") { // Rule determined manual review is needed return { status: "under_review", message: "Your request is being reviewed" };} else if (result.state === "BLOCK") { // Rule determined this is high-risk return { error: "This action has been blocked for security reasons" };}
// Track an action - rules are evaluated automaticallyconst result = await authsignal.track({ userId: "0272c312-e181-4cad-a494-43647b503a0a", action: "withdraw-funds", attributes: { deviceId: "device-abc", ipAddress: "203.0.113.1", userAgent: "Mozilla/5.0...", redirectUrl: "https://yourapp.com/callback" }});// Handle the result based on rule evaluationif (result.state === "CHALLENGE_REQUIRED") { // Rule determined a challenge is needed return { url: result.url // For pre-built UI };} else if (result.state === "ALLOW") { // Rule determined user is trusted return { success: true };} else if (result.state === "REVIEW") { // Rule determined manual review is needed return { status: "under_review", message: "Your request is being reviewed" };} else if (result.state === "BLOCK") { // Rule determined this is high-risk return { error: "This action has been blocked for security reasons" };}
Let’s walk through creating a practical rule that automatically challenges high-risk users while allowing trusted users to access your application seamlessly.
Now that you have created the rule, you’ll need to update your track action call to include some additional fields: deviceId, ipAddress, and userAgent.
const request = { userId: "dc58c6dc-a1fd-4a4f-8e2f-846636dd4833", action: "signIn", attributes: { deviceId: "<device-id>", // From __as_aid cookie if using Authsignal Web SDK userAgent: "<user-agent>", ipAddress: "<ip-address>" }};const response = await authsignal.track(request);// Handle the responseif (response.state === "CHALLENGE_REQUIRED") { // Use token with client SDK return { token: response.token };} else if (response.state === "ALLOW") { // User is trusted, proceed return { success: true };}
const request = { userId: "dc58c6dc-a1fd-4a4f-8e2f-846636dd4833", action: "signIn", attributes: { deviceId: "<device-id>", // From __as_aid cookie if using Authsignal Web SDK userAgent: "<user-agent>", ipAddress: "<ip-address>" }};const response = await authsignal.track(request);// Handle the responseif (response.state === "CHALLENGE_REQUIRED") { // Use token with client SDK return { token: response.token };} else if (response.state === "ALLOW") { // User is trusted, proceed return { success: true };}
const request = { userId: "dc58c6dc-a1fd-4a4f-8e2f-846636dd4833", action: "signIn", attributes: { deviceId: "<device-id>", // From __as_aid cookie if using Authsignal Web SDK userAgent: "<user-agent>", ipAddress: "<ip-address>", redirectUrl: "https://yourapp.com/callback" }};const response = await authsignal.track(request);// Handle the responseif (response.state === "CHALLENGE_REQUIRED") { // Redirect to pre-built UI return { url: response.url };} else if (response.state === "ALLOW") { // User is trusted, proceed return { success: true };}
Note: When using the Authsignal Web SDK, you can obtain the deviceId from the __as_aid cookie that’s automatically created on the client side.