Quickstart
This guide walks you through signing users in to a web application. It uses the authorization code flow with PKCE, which is the right choice for almost every application.
1. Create a project
Section titled “1. Create a project”- Sign in to the authN portal and choose Create project.
- Give it a name and an address, such as
acme. Your sign-in pages are then live athttps://acme.authn.co.uk. - On the project’s Getting started page, make a note of the issuer. Your OpenID Connect library finds everything else it needs from there, using the discovery document at
<issuer>/.well-known/openid-configuration.
2. Add your application
Section titled “2. Add your application”- Go to Client applications → Add application and choose the kind that matches your app. Choose Web app if your code runs on a server, Single-page app if it runs in the browser, or Native app for mobile and desktop apps.
- Add your redirect URI. This is the address in your application that authN sends people back to after they sign in, such as
https://app.example.com/callback, and it has to match exactly. - Copy the client ID. For a web app, also copy the client secret, because it’s only shown once.
3. Sign users in
Section titled “3. Sign users in”Node.js (openid-client)
Section titled “Node.js (openid-client)”import * as oidc from "openid-client";
const config = await oidc.discovery( new URL("https://acme.authn.co.uk"), process.env.CLIENT_ID, process.env.CLIENT_SECRET,);
// Start: send the person to the sign-in page.const verifier = oidc.randomPKCECodeVerifier();const challenge = await oidc.calculatePKCECodeChallenge(verifier);const url = oidc.buildAuthorizationUrl(config, { redirect_uri: "https://app.example.com/callback", scope: "openid email profile", code_challenge: challenge, code_challenge_method: "S256",});// Keep `verifier` in the user's session, then redirect to `url`.
// Back at /callback: exchange the code for tokens.const tokens = await oidc.authorizationCodeGrant(config, new URL(request.url), { pkceCodeVerifier: verifier,});const user = tokens.claims(); // sub, email, name, …In the browser (oidc-client-ts)
Section titled “In the browser (oidc-client-ts)”import { UserManager } from "oidc-client-ts";
const auth = new UserManager({ authority: "https://acme.authn.co.uk", client_id: "<your client ID>", redirect_uri: "https://app.example.com/callback", scope: "openid email profile",});
await auth.signinRedirect(); // on "Sign in"const user = await auth.signinRedirectCallback(); // on /callback4. Try it
Section titled “4. Try it”Open your application and choose Sign in, and you’ll arrive at your project’s sign-in page. Choose Create an account, sign up and confirm your email address, and you’ll be sent back to your application, signed in.
Next steps
Section titled “Next steps”- Login methods explains how to add passkeys or sign-in links sent by email.
- Design shows how to make the pages match your brand.
- Tokens describes what each token contains and how long it lasts.
- API resources covers getting access tokens for your own APIs.