Send users a sign-in link

Give users a link that signs them in to your application, connects a provider account or carries a campaign, and handle a callback that does not match.

To bring someone into your application from an email, a chat message or a QR code, send them a link to a page on your application that starts sign-in, for example https://yourapp.com/login. Each click on that link starts a new sign-in, so it works for anyone, as often as they open it.

Your start route is the page that begins the authorization request. When someone opens it, it:

  1. creates a new state and PKCE code verifier for this visit,
  2. keeps both for this browser, in an HttpOnly cookie or your server session,
  3. redirects to /o/authorize/ with that state and the code challenge.

Your callback then checks the state it receives against the one stored for this browser, and exchanges the code with the stored verifier.

Your applicationIts start route
A server-rendered web appThe login route in the Next.js, Python or Django guide
A single-page appThe code that keeps the verifier in sessionStorage before redirecting, in the React guide
A mobile or desktop appThe code that opens the system browser, in Mobile and desktop
An app using an OpenID Connect libraryThe library's sign-in call. See Any OpenID Connect library

Do not share a onefold address

onefold's sign-in and consent pages carry your request in their address, with its state and code challenge. Those belong to the browser that started the sign-in. Someone who opens a copied address can sign in and approve, but your callback finds no matching state and refuses the result. This applies to an address copied from the browser and to the link the URL Builder shows.

Turning off Require PKCE does not make an authorization URL safe to share. A state sent to everyone no longer protects your callback from a forged sign-in, and a link already sent keeps the scopes and redirect URI it was made with after you change them.

Each link is a start route. They differ in what the route adds to the request.

LinkWhat the start route adds
Sign inscope=openid identity
Connect a provider accountThe provider's scope, for example socials:discord. The provider must be turned on for the application. See Social login
A campaignThe utm_* parameters from its own address, copied onto the authorization URL. See Campaign attribution

A campaign link that also connects Discord:

https://yourapp.com/connect/discord?utm_source=newsletter&utm_campaign=spring

Its start route redirects to:

https://onefold.eitozx.com/o/authorize/?response_type=code&client_id=…&redirect_uri=…
  &scope=openid+identity+socials:discord&state=…&code_challenge=…&code_challenge_method=S256
  &utm_source=newsletter&utm_campaign=spring

Campaigns are recorded on onefold's pages, not on yours, so a start route that drops the utm_* parameters loses the campaign.

Handle a callback that does not match

When your callback receives a state that does not match the one stored for this browser, or there is none stored, the result is not yours to use:

  • Discard the code. Do not exchange it.
  • Remove code and state from the address, and send Referrer-Policy: no-referrer from the callback, so the code does not reach another site.
  • Show a page with a Sign in again link to your start route.

Compare the state with the value stored for this browser. Looking a state up by its value alone would accept a copied sign-in.

Do not redirect to the start route automatically. A missing state most often means a lost cookie, for example a different browser or blocked storage, and an automatic retry repeats the same failure without the person seeing why.

When the code exchange answers invalid_grant, start a new sign-in from your start route. Do not present the code again: a code works once and expires 60 seconds after it is issued. See Token exchange.

Try it from the portal

The URL Builder on the application's OAuth2 tab runs a test sign-in and shows the result. Its link works once, for you, so it is not a link to send to users.

On this page