# OpenID Connect (OIDC)

OpenID Connect is an identity layer on top of OAuth 2.0: an app sends people to an identity provider, and gets back an ID token, a signed JSON Web Token that says who signed in, for which app and until when. In a Meadowstack app the provider's library replaces the starter's development sign-in, and its access token goes to your api through one function, `setAccessTokenSource()`.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/glossary/openid-connect/

*The starter's one place for tokens: nothing is sent until your identity provider supplies one.*

From `templates/starter/src/shared/http.ts` in the Meadowstack repository:

```ts
 * The token: the development sign-in has none, so nothing is sent until your
 * identity provider is in place. When it is, tell this file how to get a
 * token once, where the provider starts (src/auth/auth.tsx):
 *
 *   setAccessTokenSource(() => msal.acquireTokenSilent(scopes).then((r) => r.accessToken));
 *
 * The server takes the person from that token, never from the request body.
 * docs/recipes/connect-your-data.md in the framework folder has the whole contract.
 */
import type { Person } from "../workspace/core";
import { apiUrl } from "./config";

/** Gives the token for the person a call is made for, or nothing (no Authorization header). */
export type TokenSource = (person: Person) => string | null | undefined | Promise<string | null | undefined>;

let tokenSource: TokenSource = () => null;

/** Sets where tokens come from, once, when your identity provider starts. */
export function setAccessTokenSource(source: TokenSource) {
  tokenSource = source;
```

## Why it matters in a business app

Building sign-in yourself means storing passwords, handling resets, adding multi-factor and keeping up with attacks. OpenID Connect hands all of that to a provider the company already trusts, and gives the app a standard, signed answer to "who is this?".

The specification is OpenID Connect Core 1.0 (errata set 2, dated 15 December 2023). Its flows are the Authorization Code, Implicit and Hybrid flows; a web app with a backend normally uses the Authorization Code Flow.

## How Meadowstack handles it

Meadowstack 2.1 does not implement OIDC; it leaves a clean slot for it:

- `src/auth/auth.tsx` is the [single sign-on](https://meadowstack.com/glossary/single-sign-on/) slot: keep its shape and replace the stub with the provider's library.
- `setAccessTokenSource()` (above) is called once where the provider starts, and every HTTP adapter then sends the token in the `Authorization` header.
- "The server takes the person from that token, never from the request body": the api validates the token and finds the role in your data or the provider's claims.
- `docs/recipes/connect-your-data.md` has the whole contract between the starter and your api.

Meadowstack 3.0 is coming as an update to every licence with its own sign-in; connecting a company's OIDC provider stays configuration you do.

## Common mistakes

- **Trusting an ID token without checking it.** Verify the signature, the issuer, the audience and the expiry on the server.
- **Using the ID token as an api key.** The api takes an access token meant for it.
- **Reading roles in the browser and trusting them.** Claims shown in the interface are for display; the server checks them again.
- **Tokens in logs and URLs.** They are secrets for as long as they are valid.

## The parts, and where they go

*Terms from OpenID Connect Core 1.0, and the place each one has in an app built on the starter.*

| Part | What it is | Where it goes |
| --- | --- | --- |
| openid scope | Every OIDC request must carry it | The provider's library, configured once |
| Authorization Code Flow | The browser gets a code, the code is exchanged for tokens | The provider's library or your backend |
| ID token | A JWT with claims about the sign-in | Read once to know who signed in; not sent to your api as a key |
| iss, sub, aud, exp, iat | The required claims: issuer, subject, audience, expiry, issued at | Your server checks them before it trusts the token |
| Access token | What the api accepts on each call | setAccessTokenSource() in shared/http.ts |
| Roles or groups | Claims your provider may add | Mapped onto the roles in workspace/core.tsx, checked again by the server |

## Questions

### What is the difference between OAuth 2.0 and OpenID Connect?

OAuth 2.0 lets an app get access to an api on a person's behalf. OpenID Connect adds identity on top: the ID token that tells the app who signed in.

### Which identity providers work with a Meadowstack app?

Any provider your backend can validate, as long as it gives the app a token for your api. The starter's comments name Microsoft Entra ID, Google Workspace, Auth.js and Supabase Auth.

### Should the browser or the backend exchange the code for tokens?

Either can be done safely with the provider's library; a backend exchange keeps tokens out of the browser entirely and suits apps that hold sensitive data.

## Sources

- [OpenID Connect Core 1.0 incorporating errata set 2](https://openid.net/specs/openid-connect-core-1_0.html), checked 2 December 2026

## Related

- [Google Workspace: only your company's domain](https://meadowstack.com/integrations/google-workspace/) (Integrations)
- [Microsoft Entra ID: the person from the token](https://meadowstack.com/integrations/microsoft-entra-id/) (Integrations)
- [Supabase: the rules in the database](https://meadowstack.com/integrations/supabase/) (Integrations)
- [Single sign-on (SSO)](https://meadowstack.com/glossary/single-sign-on/) (Glossary)
- [Permissions checklist for apps built with AI](https://meadowstack.com/tools/permissions-checklist/) (Tools)
- [A secure vibe coding checklist for business apps](https://meadowstack.com/blog/secure-vibe-coding-checklist/) (Blog)
