Skip to content

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. Sign in to the authN portal and choose Create project.
  2. Give it a name and an address, such as acme. Your sign-in pages are then live at https://acme.authn.co.uk.
  3. 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.
  1. 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.
  2. 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.
  3. Copy the client ID. For a web app, also copy the client secret, because it’s only shown once.
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, …
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 /callback

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.

  • 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.