Docs · Quickstart
Add sign‑in in ten lines
Host one JSON file, point any OpenID Connect library at happauth.com, and send your Sign in button there. There is no form, no secret and no approval.
The ten lines
With openid-client 6. Lines 2–3 find hAppAuth, 4–7 send the person to it, 8–10 turn the code into the person. callbackUrl is the URL hAppAuth sent the person back to, and the verifier lives in their session between the two requests.
import * as oidc from "openid-client";
const config = await oidc.discovery(new URL("https://happauth.com"),
"https://yoursite.example/oauth/client.json", undefined, oidc.None());
const verifier = oidc.randomPKCECodeVerifier();
const signInUrl = oidc.buildAuthorizationUrl(config, { scope: "openid profile",
redirect_uri: "https://yoursite.example/callback", code_challenge_method: "S256",
code_challenge: await oidc.calculatePKCECodeChallenge(verifier) });
const tokens = await oidc.authorizationCodeGrant(config, callbackUrl,
{ pkceCodeVerifier: verifier });
const { sub } = tokens.claims()!;
Host your client metadata
Your client id is the HTTPS URL of a small JSON document on your own site (a client ID metadata document). hAppAuth fetches it when a person first signs in; there is nothing to register.
https://yoursite.example/oauth/client.json { "client_id": "https://yoursite.example/oauth/client.json", "client_name": "Your site", "client_uri": "https://yoursite.example", "logo_uri": "https://yoursite.example/logo.png", "tos_uri": "https://yoursite.example/terms", "policy_uri": "https://yoursite.example/privacy", "redirect_uris": ["https://yoursite.example/callback"], "grant_types": ["authorization_code"], "response_types": ["code"], "token_endpoint_auth_method": "none" }client_nameandlogo_uriare what people see: hAppAuth’s sheet leads with your name and logo (PNG, JPEG, GIF or WebP, up to 64 KB; never SVG), your hostname beneath them, and our small signature at its foot.client_idmust be the document’s own URL. Keep redirect URIs on the same origin; a redirect tolocalhostworks for development and shows the person a warning line. The document is fetched with a 5 KB cap, no redirects and a short timeout, and cached by its HTTP headers.tos_uriandpolicy_uriput your own terms on the sheet, under your name: “By continuing you accept Your site’s terms · privacy policy”. Keep them on your own origin. With them there, your site needs no sign-in page to carry its terms.Point the library at the issuer
The issuer is
https://happauth.com. Discovery, keys and endpoints come from its metadata:Terminal curl https://happauth.com/.well-known/openid-configurationThe same flow, spread over the routes a server needs. Every Sign in on your site links to
/sign-in:server.ts import * as oidc from "openid-client"; const SITE = "https://yoursite.example"; const HOME = "/dashboard"; // where your header's Sign in lands const config = await oidc.discovery( new URL("https://happauth.com"), // the issuer `${SITE}/oauth/client.json`, // your client id: a URL you host undefined, oidc.None(), // a public client: no secret ); // A return is a path on your own site: "/projects/x", never "//other.example" or a full URL. function returnPath(value: string | null): string { return value?.startsWith("/") && !value.startsWith("//") && !value.startsWith("/\\") ? value : HOME; } // GET /sign-in?return=/projects/x — every Sign in button links here, straight to hAppAuth. export async function signIn(request: Request, session: Session) { const verifier = oidc.randomPKCECodeVerifier(); const state = oidc.randomState(); const returnTo = returnPath(new URL(request.url).searchParams.get("return")); session.set("signin", { verifier, state, returnTo }, { maxAge: 600 }); // ten minutes, server-side return Response.redirect(oidc.buildAuthorizationUrl(config, { redirect_uri: `${SITE}/callback`, scope: "openid profile email", code_challenge: await oidc.calculatePKCECodeChallenge(verifier), code_challenge_method: "S256", state, })); } // GET /callback — the code becomes a verified person, back where they meant to go. export async function callback(request: Request, session: Session) { const pending = session.take("signin"); if (!pending) return Response.redirect(`${SITE}/sign-in`); // expired: start again try { const tokens = await oidc.authorizationCodeGrant(config, new URL(request.url), { pkceCodeVerifier: pending.verifier, expectedState: pending.state, }); session.set("user", tokens.claims()!.sub); // sub, auth_time, and what you asked for return Response.redirect(`${SITE}${pending.returnTo}`); } catch { // Cancelled, or the answer did not verify: one line and a retry, and nothing changed. return Response.redirect(`${SITE}/sign-in-failed?return=${encodeURIComponent(pending.returnTo)}`); } } // POST /sign-out — end your session and go home. export function signOut(session: Session) { session.destroy(); return Response.redirect(SITE); }Your Sign in goes straight to hAppAuth
Link every Sign in on your site to your
/sign-inroute. The person goes straight to hAppAuth’s sheet at happauth.com, which leads with your name and logo, and comes back signed in, where they meant to go. hAppRadar signs in this way.- The header’s Sign in lands on your signed-in home (
/dashboardin the sample). - A Sign in that starts something says where to come back:
/sign-in?return=/projects/x#rate. The return is a path on your own site, held server-side with the PKCE verifier and the state for ten minutes. - A sign-in that fails (cancelled, expired) comes back to one line and a retry. Nothing changed.
- Sign out ends your session and goes home.
For your header, the compact ink button: our lock and your own “Sign in”. Or keep a button of your own, worded and styled as your site does; the sheet still leads with you.
Offering more than one way to sign in? Place the hAppAuth button beside the others, so people recognise their hAppAuth account, and use it as it is.
Three variants: Ink, compact (36 px), for your header; Emerald on light grounds and White on dark grounds and beside other providers (44 px). English and Turkish. Coming: the 2 KB web component and the SVG set
- The header’s Sign in lands on your signed-in home (
What comes back
The ID token always carries sub, auth_time, and acr and amr, which say how the person signed in. Ask for more with scopes; the person sees one line for each and can turn the optional ones off. Refusing an optional claim still signs them in, so read what you received, not what you asked for.
| Scope | Claims | The person sees |
|---|---|---|
openid | sub, auth_time | Your ID for this site (required) |
profile | name, picture | Your name and picture |
email | email, email_verified | Your email address |
github | github: { id, login, created_at } | Your GitHub account |
offline_access | A refresh token | Stay signed in while you’re away |
More scopes, the assurance values and the subject rules are on OpenID Connect for Holochain.
Rules the provider keeps
- Authorization code with PKCE (S256) for every client. No implicit grant, no password grant.
- Codes work once and expire in 60 seconds. Every authorization response carries
iss; openid-client checks it for you. - Access tokens are JWTs that live 5 minutes and name one audience. Refresh tokens rotate, and reusing an old one revokes the family.
- A third-party site gets a pairwise
sub: the same person has a different id on every site.