The skill, sign-in.md and the porting checklist say to name the sign-in provider or button "Core SSO" or "Authelia", so it reads the same in every app; the sso examples' link says "Sign in with Core SSO". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8.4 KiB
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://<name>.<domain>/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:
[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/<provider key>; 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_*. Set
their provider name or button label to "Core SSO" (or "Authelia"), and
check how it reads on the app's sign-in page; where it's built into the
app's own code, word its button "Sign in with Core SSO". 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(withemail_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. groupsisnullon today's Cores, not a list: they have two groups,adminsandeverybody, 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 onnull(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
adminsgroup would do it (the user decides). - Discovery:
$OIDC_ISSUER/.well-known/openid-configuration. The Core routesauthelia.<domain>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
emailAuthelia 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_EMAILthe 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 inoidc.py. - In an upstream image you can't change, use what it offers, in this
order: a setting that names admins by email; its CLI or API at startup
(making
CORE_ADMIN_EMAILan admin before anyone signs in); and if the rule has to hold on every sign-in and the app has no hook for it, a database trigger on its users table that touches only theCORE_ADMIN_EMAILrow (role, enabled, no password), made at startup by the entrypoint and explained in a comment. Say in your report which you used.
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@<domain>, display name coreapp.test, in no groups; made
on the Core in the VM when first needed, with a new password each time;
it has a mailbox, read with coreapp inbox).
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).
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://<name>.<domain>/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. Forms with fields
to fill (a password form beside the button) are ignored, so a page with
one button and a password form needs nothing more; only with several
buttons, pick one with
--form <action>. 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 ($TMPDIRcan differ between a sandboxed shell andcoreapp's). - "Signed in" needs the app to have kept the person: if its page offers
sign-in again (its callback failed quietly),
coreapp signinsays "Not signed in ... offers sign-in again";coreapp logshas 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 --codestarts 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/<key>/callbackwithcodeandredirect_url). Itsstateisn'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@<domain> 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] pkcedoesn'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,
--formfor a page with several buttons, or--codefor a single-page app.