> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom OIDC Provider

**Note: This is an advanced feature!** We recommend sticking with the
[supported third-party authentication providers](https://docs.bijection.com/access/authentication).

Bijection can be integrated with any identity provider supporting the
[OpenID Connect](https://openid.net/connect/) protocol. At minimum this means
that the provider can issue
[ID tokens](https://openid.net/specs/openid-connect-core-1_0.html#IDToken) and
exposes the corresponding
[JWKS](https://auth0.com/docs/secure/tokens/json-web-tokens/json-web-key-sets).
The ID token is passed from the client to your Bijection backend which ensures that
the token is valid and enables you to query the user information embedded in the
token, as described in [Auth in Functions](https://docs.bijection.com/access/authentication/functions.md).

## Server-side integration

Just like with [Clerk](https://docs.bijection.com/access/authentication/providers/clerk.md) and [Auth0](https://docs.bijection.com/access/authentication/providers/auth0.md), the
backend needs to be aware of the domain of the Issuer and your application's
specific applicationID for a given identity provider.

Declare the verifier with `issuer.oidc`.

```ts bijection/sign-in.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { issuer } from "@bijectionhq/bijection";

export const signIn = issuer.oidc({});
```

Place this export in the app tree in `bijection/app.ts`. After deploying, trust
the provider's values for it:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection issuer trust signIn --issuer-url https://issuer.example.com --audience your-application-id
```

Trusting an issuer issues a grant that carries `attest` for that issuer and
its values. Only the installation's identity admin issues it, never code: no
deploy and no `bijection env set` changes it. Each identity that signs in
through the issuer is bound by a grant under the trust that carries `speak`
for its principal, and each session is a grant under that binding, so
revoking the trust ends every binding and session under it.

The `--audience` value must exactly match the `aud` field of your JWT and
the `--issuer-url` value must exactly match the `iss` field of the JWT. Use a tool
like [jwt.io](https://jwt.io/) to view an JWT and confirm these fields match
exactly.

If multiple providers are provided, the first one fulfilling the above criteria
will be used.

If you're not able to obtain tokens with an `aud` field, you'll need to instead
configure a [Custom JWT](https://docs.bijection.com/access/authentication/custom-jwt.md). If you're not sure if
your token is an OIDC ID token, check
[the spec](https://openid.net/specs/openid-connect-core-1_0-final.html#rfc.section.2)
for a list of all required fields.

OIDC requires the routes `${url}/.well-known/jwks.json` and
`${url}/.well-known/openid-configuration`. `url` may include a path like
`https://your.issuer.url.com/api/auth`. This isn't common for third party auth
providers but may be useful if you're implementing OIDC on your own server.

For a native sign-in source, set `backChannelLogout: true` and register
`<installation API URL>/api/bijection/identity/backchannel-logout` with your
issuer to receive OIDC back-channel logout. The receiver verifies the signed
logout token against the installed issuer and client. The same registration
works for an issuer served by the deployment itself.

### Declare a durable authorization-code exchange

For native sign-in, add one receiver for the token URL in the issuer's
discovery document. The receiver declaration separates the HTTPS origin and
literal POST path.

```ts bijection/sign-in-receiver.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { operation, receiver } from "@bijectionhq/bijection";

export const identityToken = receiver({
  endpoint: "https://issuer.example.com",
  operations: {
    sessionExchange: operation({ path: "/oauth/token", args: {} }),
  },
});
```

Place the receiver in the installed app tree. Sessions supplies the private
authorization-code request, opens the exact provider credential if required
and holds the reply for its continuation. For a confidential client, declare
`auth.kind` as `"oauth2"`, set `tokenEndpoint` to this full URL and set
`clientId` and `clientSecret` to the source's exact client and named secret.
The client secret uses form-body authentication. A source that renews or
revokes provider grants declares separate one-operation receivers named
`sessionRefresh` or `sessionRevocation` with the appropriate fixed
endpoint.

To receive Continuous Access Evaluation Profile (CAEP) events, declare
`caepEvents` on the provider and register
`<installation API URL>/api/bijection/identity/events/caep` as the push
(RFC 8935) delivery endpoint with your event transmitter:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
caepEvents: {
  issuer: "https://signals.example.com",
  audience: "urn:example:app",
  jwksUrl: "https://signals.example.com/jwks",
  sessionIdentifier: "providerSid",
  credentialChange: "requireReauthentication",
}
```

`session-revoked` ends the subject's native sessions. `sessionIdentifier:
"providerSid"` limits a session-scoped event to sessions signed in under that
provider `sid`. `"subject"` ends every session of the subject.
`credentialChange`, `assuranceLevelChange` and `tokenClaimsChange` each take
`endSessions` or `requireReauthentication`. Other events are acknowledged
without effect.

## Client-side integration

Give the [typed client](https://docs.bijection.com/clients/typescript.md) an auth adapter as its
`token`: `connect(url, { token: auth })`. The client asks the
adapter for the current token on every request and live connection.
`authkit()` and `clerk()` from `@bijectionhq/bijection/client` read the state
of their provider's React hook (`useClientAuth(auth, state)` in a component
inside the provider). [AuthKit](https://docs.bijection.com/access/authentication/providers/authkit/existing-app.md)
also supplies session evidence through provider callbacks. For any other
provider, implement `ClientAuth`. Have `token({ refresh })` return the
current token, return `null` when signed out, and reject if a signed-in
credential is unavailable. Use `subscribe(changed)` to call `changed`
synchronously when the principal, session, or audience changes.
Keep that generation stable across ordinary token refreshes. A server or test
that holds a fixed token passes it as a string: `connect(url, { token })`.
For sessions using Bijection Auth, use its [React integration and browser
proofs](https://docs.bijection.com/access/authentication/providers/bijection-auth#quick-start).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.