Prerequisites
- sajn Login enabled for your organization (our team does this — see Overview)
- An approved client with its
client_idand secret. Create one under Inställningar → Utvecklare → sajn Login, then submit it for review. - A redirect URI registered on that client. Use
http://localhost:3000/callbackwhile developing — plainhttpis accepted on localhost only.
Use a library, if you can
sajn Login is a standard OIDC provider. Most frameworks need only the issuer URL:1. Send the user to authorize
Generate a PKCE verifier and challenge, keep the verifier server-side, then redirect:Generating the PKCE pair
2. Receive the code
state matches what you stored. If the login failed, you get ?error=… instead — see
Errors.
3. Exchange the code, from your server
Response
4. Use the result
Validate theid_token against our JWKS and read the claims:
iss, aud, exp and — if you sent one — nonce. Never trust an
unverified token, and never trust the browser redirect on its own.
Common mistakes
invalid_request: redirect_uri is not registered
invalid_request: redirect_uri is not registered
https redirect URIs must match exactly — no extra path, no trailing slash, no query
string. https://app.acme.se/callback does not match https://app.acme.se/callback/.invalid_request: code_challenge is required
invalid_request: code_challenge is required
PKCE is mandatory for every client. Enable it in your library.
invalid_grant on token exchange
invalid_grant on token exchange
The code was already used, expired after 60 seconds, or
redirect_uri does not match the one
from the authorize request. It must be byte-identical.The user authenticated but nothing came back
The user authenticated but nothing came back
If they closed the browser after BankID, the redirect never fired. Subscribe to the
login.completed webhook to catch that case.Next steps
OpenID Connect reference
Every endpoint and parameter in detail
Scopes and claims
What you can request, and what you get
Testing
Create a test BankID and run the flow end to end
Webhooks
Catch logins whose redirect never arrives

