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()`.
By Bohuslav PoláčekChecked
* 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.tsxis the 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 theAuthorizationheader.- "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.mdhas 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
| 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 |
Sources
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.
Two ways
Build it yourself, or have it built
Build it yourself
Build your app on the framework
Get the codebase these apps stand on and build yours with Claude Code, Cursor or Codex.
One payment, lifetime updates
Get the frameworkHave it built
Have us build your app
Tell us how your team works. We plan the app with you and build it on the same framework at a fixed price.
After launch, Care keeps it improving, from €99 a month.
from €1,990
Describe your app