# Sign-in with Core accounts: the details Read this when the app has `needs = ["sso"]`: to fit the Core's client to the app, to put the admin and role rules into the app, and to test sign-in. SKILL.md has the summary. ## Fitting the client to the app The Core's client, by default: redirect URI exactly `https://./auth/callback` (`$APP_URL/auth/callback`), authorization code flow, PKCE with S256 required, the secret sent with `client_secret_basic` (in the Authorization header). If the app's sign-in can't be configured to match (many have a fixed callback path, and many don't send PKCE), change the client in `coreapp.toml` instead of working around it in the app: ```toml [sso] callback = "/auth/openid/core" # the app's callback path (default "/auth/callback") pkce = false # the app doesn't send PKCE (default true) token_auth = "client_secret_post" # it sends the secret in the form (default client_secret_basic) ``` Set only what the app needs, and say in a comment why. Find out from the app's documentation or source: - the callback path it puts in `redirect_uri` (sometimes built in the browser, e.g. `/auth/openid/`; then pick the key so the path is known), - whether it sends `code_challenge`, - how it sends the secret. Authelia checks the redirect URI when sign-in starts (an error page instead of its login page if it's wrong), but PKCE and the secret only after the person has signed in, so a curl of the authorize URL can't show those are right; `coreapp signin` can. Changing `[sso]` and deploying registers the client again; Authelia restarts for it (a few seconds of 404s from it). Many apps fetch discovery only once at startup: wait for it in the entrypoint (SKILL.md, "Wait for what it needs at startup"). Use the app's own OpenID Connect support or its framework's library: most self-hosted apps have "generic OIDC" settings that map onto `OIDC_*`. If the app has its own step for setting up its client (an admin makes a secret in its settings, or pastes a client block into the identity provider), skip it on the Core: fill its settings from `OIDC_*`, so sign-in works with no admin step, and don't show those instructions when the Core gave the client. `coreapp new --sso example` makes a standard-library Python example of the whole flow (`oidc.py`). ## What Authelia says about the person - Scopes: `openid profile email groups`. The claims come from the userinfo endpoint: `sub`, `email` (with `email_verified: true`), `name` (the account's uid, e.g. `coreapp.test`), `preferred_username` (the email address, which is what people sign in with), `groups`. The ID token has none of them, so an app that reads the person only from the ID token gets no email or name: turn on its "use userinfo" setting. - `groups` is `null` on today's Cores, not a list: they have two groups, `admins` and `everybody`, but Authelia's settings don't find them yet (for Federated to fix). Don't turn on an app's group-to-role mapping: apps that expect a list fail every sign-in on `null` (Miniflux: "groups must be a string or a list of strings"). - An app that can make admins only from a group (no way to name one by email) can't follow the admin rule yet: leave its admins off, say so in your report, and note that once groups work, mapping the Core's `admins` group would do it (the user decides). - Discovery: `$OIDC_ISSUER/.well-known/openid-configuration`. The Core routes `authelia.` from inside the app's container to the real HTTPS endpoint, with a valid certificate, so normal TLS verification works. - Sign-out in the app ends the app's session; the person stays signed in to the Core. ## Putting the admin and role rules into the app The rules are in SKILL.md: `CORE_ADMIN_EMAIL` is always an admin, everyone else gets the lowest role that can look around. How: - Check the admin on every Core sign-in, from the `email` Authelia gives (compared case-insensitively), and make that account an admin (back) if it isn't. Never from an address typed into the app: no local account, sign-up or invitation with that address becomes an admin. - If the app has its own first-run setup (an owner to create, a setup link), skip it on a Core: the Core's admin is the owner. If the app can't run without an owner (its pages say "not set up" until there is one), make `CORE_ADMIN_EMAIL` the owner at startup, without a password. - That account signs in only with the Core: turn off the app's password sign-in and password reset for it, or its forgot-password page could give it a local password. - Other Core accounts join on their first Core sign-in, without an invitation, as read-only members (a viewer: they see what members see, change nothing). Not "nothing until an admin grants access". - The example app (`coreapp new --sso`) shows the admin check in `oidc.py`. ## Testing sign-in: coreapp signin `coreapp signin` signs in to the app as a browser would, on the real Authelia with the app's real client, as the Core's test account (`coreapp.test@`, display name `coreapp.test`, in no groups; made on the Core in the VM when first needed, with a new password each time). It prints each step, with Authelia's error if the client doesn't fit, and says whether it got back to the app signed in. Run it in the app's folder (it reads `coreapp.toml`). ```bash coreapp signin # starts at /login coreapp signin /auth/login # the app's own page that starts sign-in coreapp signin /signin # a page whose button starts sign-in: pressed jar=$(mktemp) && coreapp signin --cookies "$jar" /login && curl -b "$jar" https://./api/me ``` - A page with a sign-in button (a form with only hidden fields, such as a CSRF token) is submitted as a person pressing it would; with several such forms, pick one with `--form `. Don't add routes to the app just for the test. - With `--cookies`, check what the test account may do: it should land as a read-only member. Keep the jar's path in one command, as above (`$TMPDIR` can differ between a sandboxed shell and `coreapp`'s). - "Signed in" needs the app to have kept the person: if its page offers sign-in again (its callback failed quietly), `coreapp signin` says "Not signed in ... offers sign-in again"; `coreapp logs` has the app's reason. - Apps whose sign-in starts in the browser's JavaScript (single-page apps: the page builds the authorize URL itself): `coreapp signin --code` starts at Authelia with the app's client and stops at the app's callback, printing it with the code; give that to the app as its page would (e.g. Vikunja's: `POST /api/v1/auth/openid//callback` with `code` and `redirect_url`). Its `state` isn't the app's, so a server-side callback that checks state refuses it: use the path form for those. - Authelia bans an account for a few minutes after repeated failed sign-ins, so don't loop on it. The test account isn't the admin, so ask the user to sign in once in a browser as `admin@` before a release: it checks what a script can't (the app's pages, and that the admin gets the admin role). ## When sign-in fails `coreapp signin` shows Authelia's error and hint: - "The 'redirect_uri' parameter does not match": the app's callback isn't the client's (`[sso] callback`). - "invalid_client": it sends the secret another way (`[sso] token_auth`). - A PKCE error: `[sso] pkce` doesn't match what the app does. - "didn't lead to the Core's sign-in": the path doesn't start sign-in; give the right one, `--form` for a page with several buttons, or `--code` for a single-page app.