# AuthID server integration examples

Five languages, three integrations: OIDC, SAML, and signed permission decisions.
These are backend integration modules, not complete web applications. Your framework
supplies routes, cookies, CSRF protection and an authenticated application session.

## Configuration

Use your developer workspace to verify a website, register SAML entity/ACS/public
certificate or an OIDC callback, and create a least-privilege server API key.
Keep all private keys and API/client secrets in your backend's secret manager.

Environment names in the examples:

- AUTHID_APPLICATION_ID: application UUID from the workspace.
- AUTHID_API_KEY: server API key scoped to permissions:read.
- AUTHID_STATE_DB: absolute path to a persistent local SQLite database.
- AUTHID_CHECKPOINT_DIR: persistent checkpoint directory for the Node permission client.
- AUTHID_SAML_ENTITY_ID, AUTHID_SAML_ACS_URL: exact registered SP identifiers.
- AUTHID_IDP_CERT_FILE: pinned customer IdP public certificate from app metadata.
- AUTHID_SP_KEY_FILE, AUTHID_SP_CERT_FILE: matching SP RSA private key and public certificate files.
- AUTHID_OIDC_CLIENT_ID, AUTHID_OIDC_CLIENT_SECRET, AUTHID_OIDC_REDIRECT_URI: confidential client settings.

Customer issuer: https://auth.identiblok.com. Do not use staff SSO metadata.
Use OIDC scopes `openid profile`, not `email`. Callbacks must be HTTPS, without
fragments; these examples use callback URLs without query parameters.

## Browser and session contract

Generate 32 random bytes, encode as unpadded base64url (43 characters), and set a
five-minute `__Host-authid-tx` cookie: Secure, HttpOnly, Path=/, no Domain attribute.
SAML requires SameSite=None for its cross-site POST; OIDC GET can use SameSite=Lax.
Pass that cookie value into begin and complete. Reject missing cookies and duplicate
callback fields. Never accept a binding supplied through query or form parameters.

Do not create your app session until complete returns a verified AuthID. Rotate the
app session ID, delete the transaction cookie, and use a separate protected session
cookie. Keep normal CSRF protection on app actions. SAML single logout is not
supported; logging out of your app requires clearing its own session.

Permission subjects must come from the verified server session. `require` or
`require_permission` throws on denied access, invalid signatures, stale responses,
wrong request parameters, rollback or unavailable checkpoint storage. Propagate
failures as access denied. Do not cache positive permission decisions.

## Storage contract

SQLite and Node file adapters are for one persistent host. They are unsuitable for
Vercel ephemeral filesystems. Multi-host/serverless users must supply shared durable
storage. Login transaction operations:

- put(key, value, ttl_seconds): insert only if absent; return true on success.
- get(key): return the unexpired string or null/None.
- take(key): atomically delete and return the unexpired string; one caller wins.

Permission checkpoint `advance(scope, height, block_hash)` must atomically reject a
lower height or a conflicting hash at the same height. Persist the accepted value
before returning true. Node's existing CheckpointStore receives a `{height, hash}`
object instead. Store outages must throw or fail closed, never reset checkpoints.
Protect database files with OS permissions and backups. Transaction values include
OIDC PKCE secrets; never log them. A failed OIDC callback consumes its transaction;
start a fresh login instead of retrying the same authorization code.

## Packages

Node.js/TypeScript: published @identiblok/authid 0.1.0 for SAML/permissions,
openid-client 6 for OIDC. Node examples require Node 24 for node:sqlite.
Python, Ruby and Rust: install the versioned packages supplied with this guide.
The APIs provide verified sign-in and permission checks plus a bounded generic
/v1 API request helper. Webhook and ledger-block helpers are currently Node-only.
The network remains a single-authority signed ledger, not decentralized consensus.


## Enterprise organization sign-in

`node-enterprise-sso.mjs` and `python-enterprise-sso.py` use the standalone profile
handoff. `node-enterprise-oidc.mjs` and `python-enterprise-oidc.py` demonstrate
organization-bound hosted OIDC. Install the versioned server packages from the
[management downloads](https://identiblok.com/docs/management#sdk). Node hosted
OIDC also requires openid-client 6 and the adjacent SQLite adapter.

Set AUTHID_ORGANIZATION_ID and AUTHID_CONNECTION_ID from trusted server
configuration, plus the existing application/client/callback/storage variables.
Use a five-minute SameSite=Lax transaction cookie for these GET callbacks. Keep
all scope IDs with the verified `ibk_ent_` subject in the application session.
Python standalone completion is asynchronous. These modules need the routes,
secure cookies and application session supplied by your framework.

See [the complete guide](https://identiblok.com/downloads/management/enterprise-sso-integration.md) for provider
settings, exact protocol limits, invitation-only flows and permission checks.
