Auth.js: eigen OIDC-provider met volledig Next.js-voorbeeld
Inloggen met Dazr Identity: gratis OpenID Connect, gehost in de EU, met passkeys, e-mailcodes en Google- of Microsoft-accounts achter één knop.
Je hebt drie waarden uit de ontwikkelaarsconsole nodig: de client-ID, het clientgeheim (alleen voor webserver-apps) en de redirect-URI die je hebt geregistreerd. De rest staat in het discovery-document op https://identity.dazr.eu/.well-known/openid-configuration.
Auth.js / NextAuth
Auth.js (NextAuth.js v5) accepteert een eigen OpenID Connect-providerobject. Registreer een webserver-app, stel AUTH_SECRET, AUTH_DAZR_ID en AUTH_DAZR_SECRET in en gebruik deze callback-URL als redirect-URI: https://app.example.eu/api/auth/callback/dazr.
// auth.ts
import NextAuth from "next-auth"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
{
id: "dazr",
name: "Dazr Identity",
type: "oidc",
issuer: "https://identity.dazr.eu",
clientId: process.env.AUTH_DAZR_ID,
clientSecret: process.env.AUTH_DAZR_SECRET,
authorization: { params: { scope: "openid profile email" } },
checks: ["pkce", "state", "nonce"],
client: { id_token_signed_response_alg: "ES256" },
},
],
})
NextAuth.js v4 werkt op dezelfde manier, met type: "oauth" en de discovery-URL:
// pages/api/auth/[...nextauth].ts (NextAuth.js v4), in providers: [ ... ]
{
id: "dazr",
name: "Dazr Identity",
type: "oauth",
wellKnown: "https://identity.dazr.eu/.well-known/openid-configuration",
clientId: process.env.DAZR_CLIENT_ID,
clientSecret: process.env.DAZR_CLIENT_SECRET,
authorization: { params: { scope: "openid profile email" } },
idToken: true,
checks: ["pkce", "state"],
client: { id_token_signed_response_alg: "ES256" },
profile(profile) {
return { id: profile.sub, name: profile.name ?? null, email: profile.email }
},
}
Next.js App Router
Voeg met het bestand auth.ts hierboven de route handler toe en een inlogknop die een server action uitvoert.
// app/api/auth/[...nextauth]/route.ts
import { handlers } from "@/auth"
export const { GET, POST } = handlers
// app/page.tsx
import { auth, signIn, signOut } from "@/auth"
export default async function Page() {
const session = await auth()
if (session?.user) {
return (
<form action={async () => { "use server"; await signOut() }}>
<p>Signed in as {session.user.email}</p>
<button type="submit">Sign out</button>
</form>
)
}
return (
<form action={async () => { "use server"; await signIn("dazr") }}>
<button type="submit" className="dazr-signin">Sign in with Dazr Identity</button>
</form>
)
}
Geef de knop de stijl uit De knop. In callbacks is de Dazr-sub gelijk aan account.providerAccountId.
sub is pairwise: hetzelfde voor elke app van je organisatie, anders voor elke andere organisatie. Hij verandert nooit voor een persoon, een e-mailadres wel. Sla sub op als sleutel van het account en behandel email als contactgegeven.
Meer voor ontwikkelaars
OntwikkelaarsdocumentatieAlle integratiehandleidingenElke OpenID Connect-bibliotheekPrijzen