Skip to Content

sajn Login errors

OAuth error codes, BankID hint codes, and what to do about each

Where an error shows up

Three different places, and knowing which one you are looking at narrows the cause immediately:

WhereLooks likeCause
A 400 page at /oidc/authorizeJSON { "error": … } in the browserThe request could not be tied to a registered client
Your redirect_uri?error=…&error_description=…The request was valid but rejected
The token endpointJSON { "error": … } with 400/401The code exchange failed

The first case never redirects — before we have verified that a redirect_uri belongs to the client, bouncing the user anywhere would make the endpoint an open redirector.

Authorization errors

errorWhat happenedFix
unauthorized_clientUnknown client, not approved, or sajn Login is not enabled for the organizationCheck the client is Godkänd in the dashboard
invalid_requestMissing/malformed parameter, unregistered redirect_uri, or PKCE absentSee the description; usually an exact-match redirect problem
invalid_scopeUnknown scope, openid missing, or a scope the client is not approved forRequest only approved scopes
unsupported_response_typeNot codesajn Login only supports the authorization code flow
login_requiredYou sent prompt=noneSilent authentication is impossible — every login is a fresh BankID

Token errors

errorHTTPWhat happened
invalid_client401Wrong client_id or client_secret
invalid_grant400Code unknown, expired, already used, redirect_uri mismatch, or PKCE verification failed
unsupported_grant_type400Only authorization_code exists — there are no refresh tokens
invalid_request400Missing code, client_id or redirect_uri

invalid_grant is the one people hit most. In order of likelihood: the code was already used; more than 60 seconds passed; redirect_uri differs by a trailing slash from the authorize request. It must be byte-identical.

BankID hint codes

When a login fails on the BankID side, the reason appears as a hint code — on the login page, and in data.object.reason of a login.failed webhook.

Hint codeMeaningRecoverable
userCancelThe user cancelled in the appYes — they can retry
cancelledThe login was cancelledYes
startFailedThe QR code could not be readYes
noClientNo BankID app respondedYes
expiredTransactionThe app did not respond in timeNo — the session is over
certificateErrTheir BankID is blocked or too oldNo — they need a new BankID

Recoverable failures do not fire a webhook: the login page offers a retry inside the same session, and notifying on every mistyped cancel would flood your endpoint.

Session API errors

The Session API returns the same error body as the rest of the sajn API: branch on code, show userMessage to your users, and log requestId. For the full shape, see Errors.

HTTPcodeCause
400VALIDATION_FAILEDredirectUri isn't registered on the client, or the body is malformed
401UNAUTHORIZEDThe API key is missing, invalid, expired, or revoked
403PERMISSION_DENIEDThe client isn't approved, or the organization doesn't have sajn Login enabled or isn't active
403INSUFFICIENT_SCOPEAn OAuth token lacks login:write (start) or login:read (read)
404NOT_FOUNDresource is client: the clientId is unknown or belongs to another workspace. resource is login_session: the session is unknown, expired, or belongs to another workspace
429RATE_LIMITEDToo many requests. See Rate limits

A session or client from another workspace answers 404, not 403. "Exists but isn't yours" is itself information, so sajn doesn't confirm it.

Diagnosing by symptom

Everything works locally, fails in production

Production redirect URIs need to be registered too, and https matches exactly. Also check your client was switched to a production certificate — a test client will not accept real BankIDs.

The user says they logged in but nothing happened

Classic abandoned-browser case: they completed BankID and closed the in-app browser before the redirect. The authentication succeeded on our side. Subscribe to login.completed to see it.

id_token signature verification fails

Usually a cached JWKS after a key rotation. Use a client that refetches on an unknown kid rather than pinning a key. Also confirm you are validating iss as exactly https://login.sajn.se, with no trailing slash.

`sub` changed for a user you recognise

It should not — sub is stable per person per organization. If it changed, you are almost certainly comparing across two different organizations, or between a test and a production environment, which are deliberately separate identifier spaces.

The login page says the link is no longer valid

The login was already completed, or it expired (15 minutes). Start a new one — links are single-use by design, so a leaked URL is worthless.

Was this page helpful?

Last updated on