allow, step_up, review or block.
WorkOS already knows facts that make the score more accurate. Examples are whether the user verified the email and the ages of the account and the session. auth_context is the part of the assessment request that carries these facts. fromWorkOS is the WorkOS adapter in each NoResponse SDK. It builds auth_context from the AuthKit access token claims that you verified, and you add the facts from the WorkOS user and session records.
Your backend does five things:
- Verifies the access token: the signature against the JWKS of your client.
getUser: gets the account age and the verified email.- Lists the sessions of the user: gets the session age.
fromWorkOS: turns the claims and the records intoauth_context.assessments.create: NoResponse returns the assessment.
What WorkOS can supply
What WorkOS cannot supply
- A verified phone number. AuthKit users have no phone number, so
phone_verifiedstays empty. - A recent second factor. The access token and the session record do not say whether the user passed MFA, or when. Leave
mfaout unless a record of your own proves it. - The time of the last login. The access token has no
auth_time. Itsiatchanges on every refresh, so it is not the age of the session either.session_created_atcarries that age. - An assurance level. WorkOS has no equivalent of
assurance_level.
Install
TypeScript
@workos-inc/node 11, workos 10 for Python and workos-go 4.
Set three variables in the environment of your backend:
WORKOS_API_KEYandWORKOS_CLIENT_ID, from the API keys page of the WorkOS Dashboard.NORESPONSE_API_KEY, a NoResponse key with theassessscope.
NORESPONSE_API_KEY themselves. The Go client takes it as an argument. The quickstart tells you how to get a key.
Assess the new account
Assess each new account once. Do it on the first authenticated request for a WorkOS user that your database does not know yet. Do it before you create your own records for the account or give it access. The API answers within 3 seconds. The access token is theaccessToken that AuthKit returns:
authenticateWithCodereturns it at login.loadSealedSession(...).authenticate()returns it from the session cookie.withAuth()returns it in Next.js.
TypeScript
ip is the public address of the client. Behind a load balancer, read it from the header that the load balancer sets, such as the last address that it appended to X-Forwarded-For. Never read it from a value that the client controls.
The WorkOS user id is the account_id. It is stable, and the WorkOS API takes it when you act on the result later.
The flow is account creation, so NoResponse waits up to 3000 ms for its full set of sources. To wait only for the sources that answer within 500 ms, send depth: "quick". The other sources still finish later, and their results reach you through the webhook.
Act on the answer
The answer starts withassessment.account, the one current risk of the account. Your code acts on assessment.account.risk.decision, the decision for the flow that you sent:
allow: let the account in.step_up: ask for more proof first, such as a second factor.review: hold the account until your team looks at it.block: refuse the account. NoResponse answersblockafter you set a block threshold and the score reaches it.- Any other value: treat it as
review.
assessment.account.risk.score and assessment.account.risk.reasons tell you why. assessment.detail holds the facts of this assessment, such as its status, the sources that did not answer and the summary facts.
assessment.accountis absent while the first assessment of the account is still pending. Apply your fallback. Then take the final assessment from the webhook when it arrives.- If the call fails or times out, apply the same fallback.
What the adapter sends
This is theauth_context for a new user in an organization, with a verified email:
auth_context for a new user
account.risk.reasons lists each one with its weight:
auth_new_sessionandauth_new_accountraise the score for any new account.auth_email_verifiedlowers it. It makes this account different from one with nothing verified.
Next steps
Turn an assessment into a decision
Rules for
allow, step_up, review and block.Pending, retries and idempotency
What a
pending answer carries and how retries work.Pass your auth session
Every
auth_context field and the six auth reason codes.