---
title: The sign-in flow
summary: Tessera uses the OAuth authorization code flow with PKCE (S256); this page shows each request and response, so you can check what your OIDC library sends.
section: connect
order: 2
---
# The sign-in flow

Tessera uses the OAuth authorization code flow with PKCE (S256); this page shows each request and response, so you can check what your OIDC library sends.

Examples use the shared issuer `https://login.kurthlabs.com/realms/acme`, the client `acme-web` and the redirect URI `https://app.example.com/auth/callback`. On a realm with its own login domain the endpoints sit at that domain without the `/realms/<realm>` part; always read the real URLs from discovery.

## 1. Discover the endpoints

```http
GET /realms/acme/.well-known/openid-configuration HTTP/1.1
Host: login.kurthlabs.com
```

```json
{
  "issuer": "https://login.kurthlabs.com/realms/acme",
  "authorization_endpoint": "https://login.kurthlabs.com/realms/acme/authorize",
  "token_endpoint": "https://login.kurthlabs.com/realms/acme/token",
  "jwks_uri": "https://login.kurthlabs.com/realms/acme/jwks",
  "userinfo_endpoint": "https://login.kurthlabs.com/realms/acme/userinfo",
  "end_session_endpoint": "https://login.kurthlabs.com/realms/acme/logout",
  "response_types_supported": ["code"],
  "code_challenge_methods_supported": ["S256"],
  "authorization_response_iss_parameter_supported": true,
  "scopes_supported": ["openid", "profile", "email", "address", "phone", "offline_access"],
  "id_token_signing_alg_values_supported": ["EdDSA", "RS256"]
}
```

The real document has more fields; see [Endpoints](/docs/reference/endpoints.md). It is cached for one hour (`Cache-Control: public, max-age=3600`). Check that `issuer` equals the issuer you configured.

## 2. Send the person to authorize

Create three random values and keep them in the visitor's server-side session or a short-lived HttpOnly cookie:

- `code_verifier`: 43 to 128 random characters from `A-Z a-z 0-9 - . _ ~`. The challenge is `BASE64URL(SHA256(code_verifier))`, which is 43 characters.
- `state`: ties the response to this visit. Tessera refuses a request without it.
- `nonce`: ties the ID token to this visit. Optional on the wire, but send it.

```http
GET /realms/acme/authorize
  ?response_type=code
  &client_id=acme-web
  &redirect_uri=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback
  &scope=openid%20profile%20email%20offline_access
  &state=Zy3Q8dK1
  &nonce=n-0S6_WzA2Mj
  &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
  &code_challenge_method=S256 HTTP/1.1
Host: login.kurthlabs.com
```

Authorize is a browser redirect, so it takes `GET` with the parameters in the query string and answers no other method. Every endpoint your server calls directly (`/token`, `/revoke`, `/introspect`) takes its parameters in a form-encoded `POST` body instead and ignores the query string.

| Parameter | Notes |
| --- | --- |
| `response_type` | Must be `code`. |
| `redirect_uri` | Must match a registered URI exactly (scheme, host, port, path, trailing slash). One exception for native apps: a registered `http://127.0.0.1` or `http://[::1]` URI also matches the same URI with any port, because the app picks a free port at run time. `localhost` is not port-flexible. |
| `scope` | `openid` for an ID token; `profile`, `email` add claims; `offline_access` asks for a refresh token. |
| `code_challenge`, `code_challenge_method` | `S256` only. `plain` is refused. |
| `resource` | Only for an app that has an API or is an MCP client (RFC 8707). It becomes the access token's `aud` and must be one of the client's allowed resources. Repeat it for several. A plain OIDC app leaves it out. |
| `prompt` | `none`, `login`, `consent` or `select_account`. `none` cannot be combined with another value and returns `login_required` instead of showing a page. |
| `max_age`, `acr_values`, `login_hint` | Optional. `acr_values` must be a value the realm supports. |
| `response_mode` | `query` (default), `fragment` or `form_post`. |

What `resource` does depends on the client:

- **A plain OIDC app** (a client with no allowed resources, which is what `tessera init` and the console create) sends no `resource`. Its access token's `aud` is its own `client_id`, which is also what userinfo accepts.
- **An app with an API** lists the API's identifier in its allowed resources. A request with no `resource` then uses the first allowed one.
- **An MCP client** must always name its resource. See [Protect an MCP server](/docs/quickstart/mcp-server.md).

The person signs in on Tessera's hosted pages. What they see depends on the realm: with email-first sign-in they enter an email address, and Tessera either sends them on to their company's identity provider (when the address's domain is routed to one) or emails a six-digit code and a sign-in link that only work in the browser that asked; a passkey or a password can be offered too. See [Sign-in methods](/docs/concepts/sign-in-methods.md). None of this changes the requests on this page. Tessera then redirects:

```http
HTTP/1.1 303 See Other
Location: https://app.example.com/auth/callback?code=Sm3f...&state=Zy3Q8dK1&iss=https%3A%2F%2Flogin.kurthlabs.com%2Frealms%2Facme
```

Check that `state` matches the one you stored. The code is single use and expires after 60 seconds. The `iss` parameter (RFC 9207) names the issuer that answered; if your app talks to more than one issuer, compare it with the issuer you started the flow at, and discard the response when it differs. Most OIDC libraries do this for you. It also appears on error redirects.

Most mistakes in the request (an unknown client, a `redirect_uri` that is not registered, a missing `state`, a missing or malformed PKCE challenge, a scope or resource the client may not use) show a hosted error page with an `error_code` and never redirect, because the redirect target is not yet trusted. Tessera redirects with `error`, `error_code`, `error_uri`, `state` and `iss` for the outcomes your app is expected to handle: `login_required` or `interaction_required` for `prompt=none`, `access_denied` when the person declines or may not use the app, `consent_required`, and `invalid_request` for a bad `prompt` or `response_mode`.

## 3. Exchange the code

Confidential client, secret in HTTP Basic:

```http
POST /realms/acme/token HTTP/1.1
Host: login.kurthlabs.com
Authorization: Basic YWNtZS13ZWI6c2VjcmV0
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
&code=Sm3f...
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback
&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
```

A public client sends `client_id=acme-web` in the body and no secret. Confidential clients may also use `client_secret_post` or `private_key_jwt`. See [Client types](/docs/connect/client-types.md).

Send every parameter in the body, never in the query string. The `code_verifier` is the one you made in step 2: 43 to 128 characters from `A-Z a-z 0-9 - . _ ~`.

```json
{
  "access_token": "eyJ...",
  "token_type": "Bearer",
  "expires_in": 900,
  "refresh_token": "Xk9...",
  "scope": "openid profile email offline_access",
  "id_token": "eyJ..."
}
```

- `expires_in` is the realm's access token lifetime. The default is 900 seconds.
- `refresh_token` appears only when the scope includes `offline_access` and the client may use the `refresh_token` grant.
- `id_token` appears when the scope includes `openid`.
- A reused or expired code, a code issued to another client, a different `redirect_uri` or a wrong `code_verifier` all answer `400` with `error: invalid_grant`. Presenting a code a second time also revokes the refresh tokens that the first exchange produced, so a stolen code cannot be quietly replayed.
- For a plain OIDC app the access token's `aud` is the `client_id`. Roles of the apps that list the client ride on it; see [Token claims](/docs/reference/claims.md).

## 4. Validate the ID token

Your library does this. If you do it yourself, check all of these before you trust the token:

1. The signature, using the key in `jwks_uri` whose `kid` matches the token header. The algorithm is `EdDSA` by default, or `RS256` if the client is set to that.
2. `iss` equals your issuer.
3. `aud` equals your client ID.
4. `exp` is in the future (allow a little clock skew).
5. `nonce` equals the one you sent.

The header `typ` is `JWT`. Access tokens use `at+jwt`, so an ID token is never accepted as an access token. Claims are listed in [Token claims](/docs/reference/claims.md).

## 5. Read the user's details

Use the ID token claims, or call userinfo with the access token. It answers `GET` and `POST`, and a missing or invalid token gets `401` with a `WWW-Authenticate: Bearer` challenge:

```http
GET /realms/acme/userinfo HTTP/1.1
Host: login.kurthlabs.com
Authorization: Bearer eyJ...
```

```json
{
  "sub": "0194f3c2-6f1a-7c1e-9d2b-3a4b5c6d7e8f",
  "email": "ada@example.com",
  "email_verified": true,
  "preferred_username": "ada",
  "groups": []
}
```

`email` and `email_verified` need the `email` scope; `preferred_username` needs `profile`. `sub` is a stable user ID: key your accounts on it, never on the email address.

## 6. Refresh

```http
POST /realms/acme/token HTTP/1.1
Host: login.kurthlabs.com
Authorization: Basic YWNtZS13ZWI6c2VjcmV0
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=Xk9...
```

The answer has the same shape as step 3 with a new `access_token`, `id_token` and `refresh_token`. Refresh tokens rotate: store the new one and drop the old one. Presenting an old one again is treated as theft and revokes the chain. The default lifetime is 30 days.

`invalid_grant` means the grant is over: the token expired, was revoked, or the person's Tessera session ended. Clear your session and send the person to sign in again.

## Errors

Token and revoke errors are JSON with the standard `error` and `error_description` plus Tessera's `error_code` and `error_uri`. See [Error codes](/docs/reference/error-codes.md).

```json
{
  "error": "invalid_grant",
  "error_description": "authorization code is invalid or already used. Exchange each code once, within 60 seconds, from the client it was issued to, with the identical redirect_uri. A reused code also revokes what it produced; start a new authorization.",
  "error_code": "authorization_code_invalid",
  "error_uri": "https://docs.kurthlabs.com/tessera/errors/authorization_code_invalid"
}
```
