# Add Identiblok authentication to your website

These runnable starters use the bundled `@identiblok/authid-web` package. Choose
`next` (Next.js App Router + PostgreSQL) or `node` (plain HTML + persistent SQLite).
Both authenticate through Identiblok's hosted OIDC flow, establish an opaque
HttpOnly website session, check live account status, refresh tokens, and sign out.
They do not collect passwords, biometric data, or OAuth tokens in the browser.

1. Create an application in https://identiblok.com/portal/applications/new. Reserve
   your intended production origin; it does not need to be live to start testing.
2. Open **Set up AuthID → Development**, create an environment at
   `http://localhost:3000`, and create a server OIDC client with the exact callback
   `http://localhost:3000/auth/callback`. Localhost needs no DNS verification.
3. Copy `.env.example` to `.env.local` (Next.js) or `.env` (Node). Supply the
   development client credentials and keep `AUTHID_ENVIRONMENT=development`.
   Never use `NEXT_PUBLIC_` for secrets. Remote development origins require HTTPS
   and DNS verification; callback wildcards are never supported.
4. For Next.js, apply `schema.sql` in a private database with a TLS-verified URL.
   Restrict table grants to the app server and schedule expired-row cleanup.
   For Node, choose a private persistent database file on one persistent host.
5. Run `npm install`, then `npm run dev` (Next.js) or `npm start` (Node).
   Open `http://localhost:3000`. The Node starter listens only on loopback.
6. Try **Create an account**, save your passkey and recovery kit, complete any
   required verification, consent to the application and return. Open
   `/api/private`: it should return your AuthID. Sign out and confirm it returns 401.
7. Open **Production**, verify the public HTTPS origin, create a separate client,
   and complete every launch check. On your live server, set
   `AUTHID_ENVIRONMENT=production` and use the production origin, credentials and
   a separate session database. The Node starter needs an HTTPS reverse proxy
   that preserves the public Host header.

## React and non-React

The Next.js `app/providers.tsx` and `app/page.tsx` also demonstrate the React API:
`AuthIDProvider`, `SignIn`, `SignUp`, `UserButton`, `SignedIn`, `SignedOut`, and
`useAuthID`. React components require a same-origin backend with all five auth
routes; they do not implement browser-only token exchange. The Node starter
shows `mountSignIn`, `mountSignUp`, and `mountUserButton` with ordinary HTML.

The embedded card opens hosted authentication in the current tab. Passkeys are
bound to `auth.identiblok.com`, so credential prompts are never placed inside an
iframe. The account control opens the hosted device/passkey manager in a new tab.
To style your card, set `--ibk-primary`, `--ibk-ink`, `--ibk-muted`,
`--ibk-border`, `--ibk-surface`, `--ibk-tint`, and `--ibk-radius` on `.ibk-card`.
Check text/background contrast after changing colors.

## Server protection and lifecycle

Always call `auth.session(request)` in protected handlers. `SignedIn` only hides
UI. Use `@identiblok/authid` permission checks for roles/resources after taking
the subject from that verified session. Protect your own mutations from CSRF;
the SDK protects its sign-out route, not arbitrary application endpoints.

The website session has a maximum 12-hour life (configurable down to five minutes).
The server rotates five-minute access tokens under a shared atomic lock and
checks AuthID userinfo on every session read. AuthID blocking, recovery, provider
session expiry and revocation deny subsequent reads. Provider or database outages
fail closed with an error, not a guessed signed-in state. Logout destroys this
website session and attempts to revoke its OAuth family; it leaves other websites
and the hosted AuthID session signed in. Callback transactions are browser-bound,
expire after five minutes and are consumed exactly once.

Social providers are configured by the AuthID service operator. The customer
website needs only its Identiblok OIDC client. See `/docs#providers` and
`docs/social-providers.md` for provider-specific credentials, callbacks and tests.

Verify sign-in, recovery, and access controls on the devices and identity
providers your application uses.


## Development and production

Open **Set up AuthID → Development**. Create an environment with an exact local
origin such as `http://localhost:3000`, then create a confidential OIDC client
with `http://localhost:3000/auth/callback`. Use that environment's credentials
and set `AUTHID_ENVIRONMENT=development` on your local server. The SDK permits
HTTP only on loopback when this option is explicit; the AuthID issuer stays HTTPS.
For a remote development domain, use HTTPS and complete its DNS verification.

Open **Production** to configure the real HTTPS origin and a separate client.
Complete a development sign-in, verify production DNS, create the production
client, test logout/denied access, and confirm recovery/security review. The
backend blocks production sign-in until the owner completes the checklist.
Set `AUTHID_ENVIRONMENT=production`, switch `APP_ORIGIN` to the production HTTPS
origin, and install production credentials on the live backend. Use a separate
session database per environment. Test credentials and grants are never promoted.

These are isolated application environments on one AuthID service. A person's
global AuthID remains the same. Application users, grants, clients and tokens are
separate. This is not a separate physical blockchain or an independently operated
validator network. Identiblok currently uses one signing authority.
