/selise-blocks:blocks-iam-sso-oidc-implementationfrom selise-blocks
Extend or debug the scaffolded Blocks SSO/OIDC login flow: redirectToProvider, /login/callback, AuthProvider, route guards, and token refresh.
Ships in selise-blocks. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When invoking a project-scoped blocks command, either use the resolved account's saved selection or pass --project <tenantId> for that one command without changing saved state. --project applies to CLI commands only, never SDK calls.
blocks new web <name> already generates a complete, working hosted-login flow. Don't reinvent it — read what's there, extend it, or fix it. Every Blocks call in this flow goes through the single blocksClient instance (src/lib/blocks/client.ts, @seliseblocks/client); there is no raw fetch/curl anywhere in this stack.
| File | Role |
|---|---|
src/lib/blocks/config.ts | Reads VITE_BLOCKS_* env vars; isLoginConfigured() = apiUrl && oidcUrl && oidcClientId all present |
src/lib/blocks/client.ts | The one blocksClient = createBlocksClient({...}) instance, with oidc: { clientId, scope, url: oidcUrl } |
src/lib/blocks/auth.ts | startLogin, completeLogin, fetchSessionClaims, logout, getValidAccessToken — the session/token logic |
src/lib/blocks/jwt.ts | decodeJwtPayload/isJwtExpired — only relevant if a tenant's OIDC config returns bearer tokens in the body |
src/app/providers/AuthProvider.tsx | React context: status/claims/login/logout/refresh, polling + visibility-driven refresh |
src/app/router/guards.tsx | RequireAuth, RedirectIfAuthenticated |
src/app/router/routes.tsx | Wires /login, /login/callback, and the protected route table (/, /assets, /profile, /error) |
src/features/auth/LoginPage.tsx | The login button |
src/features/auth/CallbackPage.tsx | The /login/callback handler |
LoginPage's button calls useAuth().login(returnTo), which is AuthProvider's login calling startLogin(returnTo) in lib/blocks/auth.ts. startLogin throws a clear error if oidcClientId isn't set ("Login is not configured. Set VITE_BLOCKS_OIDC_CLIENT_ID in .env."), stashes returnTo (default "/") in sessionStorage, then calls blocksClient.auth.idp.redirectToProvider() with no arguments — it relies entirely on the client's configured oidc defaults.
disabled={!configured || pending} — if isLoginConfigured() is false, LoginPage renders a warning Alert with the exact callback URL ({origin}/login/callback) to register, instead of letting the click fail. "Login button does nothing" is almost always an empty VITE_BLOCKS_OIDC_CLIENT_ID.redirectToProvider() (SDK, auth-client.ts) calls auth.idp.initiate(), then window.location.assign(response.redirect_uri). initiate itself is also directly callable (e.g. to get the URL without immediately navigating, such as opening it in a new tab) but the scaffold never calls it directly; only redirectToProvider is wired to the button.<origin>/login/callback?code=...&state=.... That path is the SDK's default redirectUri — the scaffold's client.ts never passes an explicit redirectUri, so createBlocksClient derives ${window.location.origin}/login/callback at runtime (see browserRedirectUri() in the SDK's client.ts). This is exactly the route routes.tsx handles, so it lines up with zero config — but it means the OIDC client's registered redirect_uris must include /login/callback under every origin this app runs on (dev HTTPS origin and prod origin both — see the scaffold's own README and blocks-iam-sso-oidc-configuration).routes.tsx matches path === "/login/callback" and renders CallbackPage directly — not wrapped in RequireAuth or RedirectIfAuthenticated, since the user is by definition not yet authenticated when they land here.CallbackPage's one-shot effect (guarded with a useRef so React 18 Strict Mode's double-invoke doesn't run it twice) calls completeLogin(window.location.href). completeLogin reads and clears the stashed returnTo, then calls blocksClient.auth.idp.callback(callbackUrl), passing the full URL so the SDK parses code/state/error itself.
Set-Cookie on this response and returns no token in the body — completeLogin only caches a bearer token if the response body actually contains one (a non-default, explicit-token OIDC config). The SDK never stores tokens itself either way; every call sets credentials: "include" so the cookie rides along automatically once IAM has set it.data.error is present, completeLogin returns { ok: false, message } and CallbackPage shows an inline error Alert plus a button back to /login — it never silently strands the user on a blank screen.CallbackPage calls refresh() (from AuthProvider) and then onNavigate(result.returnTo). refresh() calls fetchSessionClaims() → blocksClient.auth.userInfo() to confirm the cookie actually landed and to populate claims/status before the app navigates away from the callback screen.AuthProvider is the single source of truth for status ("loading" | "authenticated" | "unauthenticated") and claims. It calls refresh() on mount, every 5 minutes (STATUS_POLL_MS, a backup interval — not the primary signal), and immediately whenever the tab regains visibility (catches sign-out in another tab or session expiry while backgrounded). It never inspects local storage to decide auth state — asking IAM directly (userInfo()) is the only source of truth, because the default flow holds no locally readable token by design.RequireAuth wraps every protected route in routes.tsx (/, /assets, /profile, /error). While status !== "authenticated" it renders LoadingScreen; once status resolves to "unauthenticated" it navigates to /login?returnTo=<currentPath> from a useEffect (not render-time — reading window.location live at render would double-nest the returnTo param under Strict Mode's double-invoked effects).RedirectIfAuthenticated wraps /login itself so an already-signed-in user hitting /login bounces straight to / instead of seeing the login button again.protectedRoutes map in routes.tsx — it's automatically wrapped in RequireAuth and AppShell by the existing router code, nothing else to wire.@seliseblocks/client methods behind all of thisAll under blocksClient.auth:
idp.initiate(request?) — starts the flow, returns { redirect_uri }. Uses the client's configured oidc defaults (clientId, redirectUri) unless you pass overrides per call.idp.redirectToProvider(request?) — calls initiate then window.location.assign(...). This is what startLogin (and therefore the login button) actually calls; reach for this directly in any new login entry point rather than re-implementing initiate+navigate.idp.callback(callbackUrlOrObject) — completes the flow. Pass window.location.href directly (what completeLogin does), or { code, state, error?, error_description? } if you've parsed the URL yourself. Returns IAM's auth response as-is; the SDK never stores tokens — your app decides what, if anything, to keep (the scaffold keeps nothing in the default cookie flow).idp.uiConfig() — public UI config (e.g. captcha settings). Not currently called anywhere in the scaffold — if you're extending LoginPage with captcha or tenant-specific login UI, call this before rendering that UI, not before.oidc.refreshToken(request?) — a separate call from the IdP-controller hosted flow, using a refresh-token grant. getValidAccessToken() in lib/blocks/auth.ts is already wired as the 401-retry/expiry path: it returns a cached, unexpired token if present, otherwise calls this (de-duplicating concurrent callers via refreshInFlight) if a refresh token happens to be cached. In the default cookie-only flow there's usually nothing cached to refresh, so this mostly matters for tenants whose OIDC config explicitly returns tokens in the response body.isAuthenticated() — returns a plain boolean. The scaffold's own fetchSessionClaims() calls the lower-level userInfo() instead (same underlying check) because AuthProvider needs the claims payload, not just a boolean — reach for isAuthenticated() yourself for a one-off check that doesn't need claims, rather than hand-rolling another call.createBlocksClient needs an oidc block: clientId (required), url (required — kept for app metadata, not used to build the authorize URL), redirectUri/scope (optional, default to ${origin}/login/callback / openid profile). The scaffold populates this from VITE_BLOCKS_OIDC_CLIENT_ID / VITE_BLOCKS_OIDC_URL / VITE_BLOCKS_OIDC_SCOPE in .env.
This clientId is the public OIDC client registered for this app — see the sibling blocks-iam-sso-oidc-configuration skill for how to resolve or create one (blocks auth oidc-clients list / save, no portal needed). Don't confuse it with blocks login itself, which authenticates the CLI with no setup and needs no registration at all (see blocks-bootstrap) — the two are unrelated and neither can substitute for the other.
--client-id and --app-domain are non-interactive-unsafe when omitted. blocks new web's client-id and domain resolution both fall back to an interactive selection prompt ("Choose an OIDC client... or create/skip" / "Multiple domains found... choose one") when the flag is missing and there's more than one candidate (or, for the client id, always — even zero candidates offers "Create"/"Skip"). There is no stdin in a non-interactive/agent-driven run, so this hangs waiting for a selection instead of quietly scaffolding with a blank/default value. A blank oidcClientId only happens if a human sitting at the terminal interactively picks "Skip". An agent running blocks new web should always resolve and pass both --client-id and --app-domain explicitly up front — see blocks-iam-sso-oidc-configuration for resolving/creating an OIDC client via auth oidc-clients list/save, and project.applications[].domain (from the project record) for the app domain — rather than omitting either and hoping for a graceful non-interactive default.
isLoginConfigured() is false, almost always because VITE_BLOCKS_OIDC_CLIENT_ID is empty in .env. Don't assume blocks new web was just run without --client-id and "left this blank on purpose" — omitting --client-id (or --app-domain, when a project has multiple domains) requires an interactive selection and fails with interactive_input_required in an agent-driven run. A blank client id only results from a human interactively choosing "Skip." Always pass --client-id explicitly (see the Config section above).http://localhost. Cross-reference blocks-frontend-local-https rather than debugging AuthProvider.redirectUri from window.location.origin at runtime; if the app runs under more than one origin (dev HTTPS host, prod domain), the registered OIDC client's redirect_uris must list /login/callback under each of them, or IAM rejects the authorize request for the ones missing./activate step first — out of scope here, see blocks-iam-account.RequireAuth/RedirectIfAuthenticated guard around /login/callback — it must stay reachable while the user is still unauthenticated, by design.blocksClient.auth.isAuthenticated() or reuse AuthProvider's status/refresh(), never infer auth state from sessionStorage/localStorage (the default flow keeps no readable token there at all).*.seliseblocks.com) app domain, the hosted-login session cookie is only stored/sent if VITE_BLOCKS_API_URL shares the app's registrable domain. The default https://api.seliseblocks.com does not share a registrable domain with e.g. abc.slsblx.com, so the browser never stores the cross-site cookie and cookie-based calls (userInfo()//iam/me, logout, the OIDC callback flow this skill documents) silently fail. For a custom domain, VITE_BLOCKS_API_URL must be https://blocksapi.<registrable-domain> (e.g. abc.slsblx.com → https://blocksapi.slsblx.com), not the default.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub selisedigitalplatforms/blocks-skills --plugin selise-blocks25 skills in this plugin
/blocksStart here for any SELISE Blocks work. Routes a plain-language request — sign-in and projects, SSO, users, roles, MFA, data schemas and records, file storage, translations, mail, notifications, workflows, functions, proxies, secrets, deployments — to the right Blocks skill, and carries the rules every Blocks skill follows: the blocks CLI and @seliseblocks/client SDK only, never raw HTTP to the platform API; --dry-run before --yes; never read the CLI's credential files; when to report a finding. Use whenever work touches SELISE Blocks, the blocks CLI, or @seliseblocks/client./blocks-bootstrapGet a user from any starting state to a working SELISE Blocks setup — CLI installed, logged in, project selected — using the `blocks` CLI, never raw fetch/curl. Detects state from `blocks auth status --json` and `blocks doctor --json`, then routes to a flow: select or create a project, inventory a project that already exists, resolve the app's OIDC client, add a social identity provider, create the first end user, scaffold a new web app, or wire an existing one. Use for a new user, for `not_logged_in`/`project_not_selected`, or whenever login/project/app state is unclear./blocks-captchaConfigure the login captcha of a SELISE Blocks project through the blocks CLI ('captcha list/get/save/enable/disable/delete'): register a reCAPTCHA or hCaptcha site key and secret, switch it on or off, see which configuration blocks-iam actually enforces at login, and retire one. CLI-only, project-scoped; the captcha secret is stored server-side and never shown. Use for 'enable captcha on login', 'change the recaptcha keys', 'why is captcha not showing', 'turn captcha off'./blocks-data-gateway-configurationConfigure a SELISE Blocks project's data model via the blocks CLI — never raw fetch/curl against api.seliseblocks.com. Covers data-source config (data config get/create/update), schema authoring and push (data schema list/pull/push, plus granular get/fields/info/indexes commands), data-access policies (data rules pull/deploy/policy), field-level validation rules (data validation *), and reloading so changes go live (data reload, or the composed data sync). Use for defining, editing, securing, validating, or reloading a project's DATA MODEL — schema fields, access policies, and validation rules./blocks-data-gateway-crudImplement create/read/update/delete against a SELISE Blocks project's runtime Data Gateway using the @seliseblocks/client SDK. Use data.collection(schemaName) for straightforward per-item CRUD, data.graphql() for joins or custom query shapes, and data.schemas.*/data.validations.* for schema/validation metadata. Shows how to wire CRUD into the React 18 + Vite + TanStack Query app that blocks new web scaffolds. Use whenever the user wants to read or write actual records through a Blocks Data schema from app code./blocks-data-storageBuild file and document-management features on SELISE Blocks Data: upload/download, directory trees, cursor-paginated browsing and search, file versions, rename/move/copy, soft delete/trash/restore, sharing, access policies, and inheritance. Use for attachments, file browsers, folders, shared files, permissions, or version history. Use 'blocks data files *' for terminal/admin work and @seliseblocks/client data.files/data.directories/data.objects for app code.Other plugins' skills for the same job