Configure authentication
Configure sign-in on the shell: backend in shellui.config.json, built-in routes at /login and /login/callback, and navigation guards. The shell stores the session, refreshes tokens, and shares the signed-in user with trusted iframe apps. Choose a provider on Connect a backend first.
For token storage, the shell-host HttpOnly refresh cookie, and shell CSP, see Security hardening.
Enable authentication
Add a backend block. Without it, useAuth() reports signed out and login actions are unavailable.
{
"backend": {
"type": "shellui",
"url": "http://localhost:8000",
"companyId": 1,
"login": {
"methods": ["oauth", "magic_link"],
"oauthProviders": ["github", "google"]
}
}
}
backend.login.methods lists what the login page may show. At runtime the shell intersects that list with backend settings so disabled providers stay hidden. When methods is missing or empty, the login page defaults to magic_link, plus oauth if oauthProviders is set.
After a magic link is sent, the login page replaces the email field with a "Check your email" message showing the address. Use a different email unlocks after 60 seconds so you can't resend links in a loop.
Staff accounts cannot use a magic link. If you request one, or open an old email link, identity-service returns magic_link_staff_disabled. The login page and /login/callback then show: "Staff accounts can't sign in with an email link. Sign in with your usual sign-in method instead."
| Method | Login UI | Notes |
|---|---|---|
oauth | Provider buttons | Needs oauthProviders and a backend-enabled provider |
magic_link | Email field | Supabase email auth; identity-service when advertised. Staff accounts are refused |
web3 | Ethereum wallet | When the backend enables it |
password | none | Typed and forwarded; the stock login view does not render a password form |
oauthProviders is an array of ids (github, google, microsoft, apple). Shellui deduplicates and lowercases them. For identity-service, per-company OAuth clients from /api/v1/settings appear as separate labeled buttons.
identity-service needs url and companyId for OAuth. Optional adminPathname / adminUrl add Administration in the account menu for staff/owners - see Administration. Supabase needs url and publishableKey.
Login routes
The shell registers these paths (urls in @shellui/core/constants/urls). You do not implement them in microfrontends.
| Path | Purpose |
|---|---|
/login | OAuth, magic link, Web3, legal links, next redirect |
/login/callback | OAuth callback (authorization code exchange) |
Protected routes redirect to /login?next=<encoded-path>. After sign-in, the shell navigates to next as an in-app path. Example: /billing → /login?next=%2Fbilling.
Login left panel
On desktop, /login shows a full-height left panel. Both branding fields are optional.
| Field | Behavior |
|---|---|
panelUrl | Full-bleed iframe. Wins when both fields are set. Must be a same-origin relative path, a configured backend/login/storage origin, or (development only) a loopback URL; untrusted URLs are ignored |
panelImage | Centered object-contain image |
| neither | Muted panel with clickable appIcon top left (links home) |
On mobile, the square appIcon is pinned top-left and the form stays centered. Language (when multiple languages are configured) and light/dark controls sit at the top right of the form column. The form uses .shellui-safe-pad for notches. Relative image paths are served from static/. The left panel is hidden on mobile and when login is embedded in a modal iframe.
login: {
methods: ["oauth"],
oauthProviders: ["github"],
panelUrl: "http://localhost:5176/login-branding/",
// panelImage: "/login-panel.jpg",
}
Optional login nav item
The shell always exposes /login. Add a nav entry to open it in the main area, a modal, or a drawer:
import type { ShellUIConfig } from '@shellui/core';
import urls from '@shellui/core/constants/urls';
const config: ShellUIConfig = {
navigation: [
{
label: 'Login',
path: 'login',
url: urls.login,
openIn: 'modal',
position: 'end',
},
],
};
When a session exists, login entries whose URL matches the shell login route are hidden from the sidebar. The header account control (avatar or Login) remains in supported layouts.
Layouts with a sidebar, app bar, or Windows taskbar render that control: signed-out users go to /login; signed-in users get profile, settings, optional administration, and logout. Logout from a requiresAuth route navigates to / first so you are not sent straight back to login.
Loading state on reload
After a page load with a stored session, the shell exchanges the refresh token before it knows who is signed in. During that first restore, the account control shows a skeleton instead of Login, login nav entries stay hidden, and Admin shows a "Restoring your session…" spinner instead of "Access forbidden". Visitors without a stored session see Login right away. Later token refreshes run in the background and never show a loading state.
Guard routes
See Navigation for the full item shape.
requiresAuth: direct navigation checks the session. While auth is loading, the route shows a fallback; when signed out, the shell redirects to /login?next=.... The iframe URL does not load until you sign in.
{
"label": "Billing",
"path": "billing",
"url": "https://app.example.com/billing",
"requiresAuth": true
}
hideWhenLoggedOut: omit the item from the sidebar and 404 suggestions while signed out. Combine with requiresAuth to hide and protect.
filterNavigationForAuthState removes hideWhenLoggedOut items when signed out and hides login nav URLs when signed in. requiresDevMode items are unchanged by auth.
Session in the host
import { useAuth } from "@shellui/core";
function Example() {
const { user, isAuthenticated, isLoading, logout, startOAuth } = useAuth();
void startOAuth;
if (isLoading) return null;
if (!isAuthenticated) return <p>Not signed in</p>;
return (
<div>
<p>{user?.email}</p>
<button type="button" onClick={() => void logout()}>
Sign out
</button>
</div>
);
}
isLoading is true only during the first session restore after a page load. Background token refreshes leave it false, so it is safe to drive loading placeholders.
When the shell host serves /api/auth (shellui start, serve:dist, or your proxy), OAuth and magic-link sign-in post the one-time shellui_auth_code and PKCE verifier to that host. Identity is called from the host, which keeps the refresh token in an HttpOnly cookie on the shell origin. The page receives the access token, expiry, and user. The access token stays in memory. The shell refreshes it 90 seconds before expiry. A new tab restores from the localStorage profile and POST /api/auth/refresh. See Security hardening for the route contract, the explicit off switch, and what to do on a static host.
Without those routes, sessions persist in browser storage. The shell refreshes access tokens before expiry while the tab is open and persists rotated refresh tokens from POST /api/v1/token.
With identity-service 0.5.0+, the default OAuth delivery is a one-time shellui_auth_code query param on /login/callback. With the host routes up, the shell posts that code to POST /api/auth/session. Otherwise it exchanges the code at POST /api/v1/oauth/session and stores the returned JSON tokens. Legacy fragment delivery (#access_token=…&refresh_token=…) still works when identity is configured with OAUTH_TOKEN_DELIVERY=fragment or token_delivery=fragment on authorize. That fragment puts the refresh token in the page. Older shells that receive provider ?code= on the frontend continue to use POST /api/v1/oauth/exchange, which also returns tokens to the page.
Browser sign-in, both social sign-in and magic link, sends PKCE S256. The start request includes code_challenge and code_challenge_method=S256, and the session exchange includes code_verifier. The verifier is stored in localStorage (shellui.auth.web.pkce) so a magic link opened in another tab of the same browser can finish. The verifier is not the refresh token.
With the host cookie, logout is POST /api/auth/logout. The host revokes the session and clears the cookie. The page does not send a refresh token. Without the host routes, logout posts the refresh token when the shell still has one (POST /api/v1/logout with Authorization: Bearer) and does not send cookies. The shell then deletes the local tokens, including the refresh token in sessionStorage.
When GET /api/v1/settings includes logout_url, the tab that signed out navigates to logout_url?company_id=<id>&return_to=<url>. return_to is on the shell origin, the same origin registered for redirect_to on /api/v1/authorize. Identity checks that allowlist and redirects the browser back. Tokens are already gone, so the page that loads is signed out and the shell does not open logout_url again. A requiresAuth route uses / as return_to, so you are not sent straight back to login. /login/callback is not used as return_to, so a leftover shellui_auth_code is not exchanged again.
An identity service that omits logout_url keeps the previous sign-out: tokens are revoked and cleared, and the page stays where it is. Other open tabs are not sent to logout_url. With BFF auth they still sign out locally when the shared refresh cookie is gone and a later refresh returns 401. The desktop app revokes tokens and stays in its window.
Register the identity callback URL on GitHub/Google/Microsoft (not each shell URL). Add every browser shell origin to the company OAuth redirect allowlist so redirect_to is accepted.
Company access pending
When identity-service uses a non-public company join mode (domain or invite), OAuth may create an account but not issue tokens for that company. Access is stored per company (CompanyMembership.is_enabled).
The backend returns error_code access_pending or access_denied (also as shellui_oauth_error_code on bounce redirects). The shell then shows a pending-access screen. After an admin enables membership, sign in again. Configure modes in admin Organization or PATCH /api/v1/companies/<id>/.
Iframe apps
Iframes do not read storage directly. They receive user through SDK settings after the shell initializes auth. The session access token is included only when the companion navigation item sets safeForAuthToken: true (opt-in). The refresh token stays in the shell and is never sent to iframe apps. An app with its own backend receives that server's URL and access token. See Apps on another identity server.
Migration (breaking change)
If your companion relied on the previous default (token shared without config), add safeForAuthToken: true on its navigation item after upgrading:
{
label: 'My app',
path: 'my-app',
url: 'http://localhost:5173/',
safeForAuthToken: true,
}
From 0.5.1 onward, postMessage origin and trusted-frame policy is on by default. The Shellui host derives companion origins from navigation, storage, and admin URLs in shellui.config.json. Add preview or staging hosts with security.allowedMessageOrigins. See SDK messaging (security.allowedMessageOrigins). Token sharing still requires safeForAuthToken: true. Allowed origins are enforced separately for postMessage traffic.
import { shellui } from '@shellui/sdk';
shellui.login({
method: 'oauth',
provider: 'github',
});
Supported method values: oauth (with provider), web3. Nested frames send SHELLUI_LOGIN to the root. After OAuth sign-in, people come back to the page they started from. Pass redirectPath (for example '/dashboard') to open another shell page instead. When backend.type is shellui, settings include authBackendBaseUrl so admin tools call the same identity base URL. An app backend replaces that URL for that frame only.
Signed-in users open Settings for account fields, theme, language, and region. Preferences sync with the backend when configured. Legal links on the login page come from legalDocuments - see Legal documents.
Apps on another identity server
Set backend on a navigation item when that embedded app signs in to a different identity server than the shell. Administration items use the same field. With no backend on the item, the shell sends its own backend URL and access token, as it does today.
{
"backend": {
"type": "shellui",
"url": "https://id.example.com",
"companyId": 1,
"login": { "oauthProviders": ["google"] }
},
"navigation": [
{
"label": "Billing",
"path": "billing",
"url": "https://billing.example/",
"safeForAuthToken": true
},
{
"label": "Directory",
"path": "directory",
"url": "https://directory.example/",
"safeForAuthToken": true,
"backend": {
"url": "https://id.directory.example",
"companyId": 4,
"provider": "google"
},
"email": { "url": "https://email.directory.example" },
"storage": {
"url": "https://files-api.directory.example",
"filesUrl": "https://files.directory.example/"
},
"hosting": { "url": "https://hosting.directory.example" }
}
]
}
Billing receives https://id.example.com, the shell access token, and the shell email, storage, and hosting URLs. Directory receives https://id.directory.example, a separate access token, and the service URLs on that item. The shell token is not sent to Directory.
| Field | Required | Description |
|---|---|---|
url | yes | Base URL of this app's identity server |
type | no | shellui or supabase. Defaults to the shell backend.type |
companyId | no | Tenant id for this server. Not copied from the shell. Omit it on the same URL to keep the shell session |
provider | no | OAuth provider for silent sign-in, such as google. upstream uses token exchange (below). Defaults to the first backend.login.oauthProviders entry |
publishableKey | supabase | Public key when type is supabase |
Optional email, storage, and hosting on the same item use the same shapes as the shell blocks. Omit a field to keep the shell service when the app uses the shell identity server. When backend names a different server and a service field is omitted, that setting is null (email included: no default URL). Set only the services that app should call. An email object without url sends null; there is no default URL. Child apps inside an embedded app get services through App frames. shellui.storage still runs against the shell storage URL.
The shell keeps one session per server. For a Shellui identity server it signs in inside a hidden frame with the same PKCE flow as desktop sign-in and prompt=none, so the identity server can return a code without showing a login page. The one-time code is posted only to the shell origin. The refresh token stays in the shell. If that sign-in does not complete, the app still receives its backend URL and accessToken: null.
Regional identity servers (token exchange)
When a regional identity server trusts the shell's global identity server, set provider: "upstream" and companyId to the company's regional id (regional_company_id, not the shell companyId). The shell then gets the app session with OAuth token exchange (RFC 8693) instead of a hidden frame:
POST {url}/oauth/token
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
subject_token=<shell access token>
subject_token_type=urn:ietf:params:oauth:token-type:access_token
company_id=<regional company id>
The shell access token goes only to that regional server, never to the app. The app receives the regional access token. When it is due, the shell renews it with the regional refresh token, kept in sessionStorage like other app sessions and never sent to the app. It exchanges again only when there is no regional session, the refresh fails, or the shell user changes. Signing out of the shell clears every regional session. A failed exchange is not retried with the same shell token. The regional server must list the shell origin (not the app origin) in OIDC_CORS_ALLOWED_ORIGINS, and needs GLOBAL_ISSUER_URL, GLOBAL_JWKS and GLOBAL_ACCESS_TOKEN_AUDIENCE. No redirect allowlist entry is needed for this flow.
safeForAuthToken: true is still required for a navigation companion. Built-in admin (backend.adminUrl) and storage files keep the shell session and shell services unless a matching item sets a different backend. Add the shell origin to that server's OAuth redirect allowlist, the same way you allow the shell backend.
A same-origin settings frame always keeps the shell session and the shell services. An item backend whose URL and type match the shell, and whose companyId is omitted or equal, is not a separate server.
Account management
With the identity-service backend (backend.type: "shellui"), Settings → user account lets users manage their own account:
- Edit name: an edit button next to the name opens an inline field. The shell saves it with
PATCH /api/v1/userand confirms with a toast. - Delete account: a Delete account button next to logout asks for confirmation, then calls
DELETE /api/v1/user. It removes the account for the current company only. A stale sign-in prompts the user to sign in again, and the only owner of a company must make another member an owner first.
Both requests are accepted only from the shell window or its own Settings frame, never from embedded apps. In host code, useAuth() exposes supportsProfileUpdate / updateProfile and supportsAccountDeletion / deleteAccount. Supabase backends hide both controls.
Desktop sign-in
Inside a Tauri webview, set auth.desktopScheme to the custom scheme registered on the OAuth application (desktop_redirect_scheme). The shell opens the system browser and returns on a deep link. Desktop sign-in runs only when backend.type is shellui. A browser tab ignores this field, including a tab opened from a Tauri-targeted build. Plugin setup is in Desktop app.
Checklist
- Run identity-service or Supabase and set
backend.type,url, and provider keys - Set
backend.login.methodsandoauthProvidersto match the backend - Mark sensitive nav items with
requiresAuthand optionallyhideWhenLoggedOut - Test a signed-out deep link (
/billing→ login → return) - In embedded apps, read the signed-in profile from SDK settings and call
shellui.login()for OAuth