Single sign-on (OIDC)
LibrePhotos can hand login over to an external identity provider that speaks OpenID Connect β Keycloak, Authentik, Authelia, Zitadel, Okta, Google, Entra ID and so on. After the provider confirms who someone is, LibrePhotos issues its own normal session, so everything downstream behaves exactly as it does for a password login.
Username-and-password login keeps working alongside it. Turning SSO on does not take anyone's existing way of logging in away.
What you need before startingβ
- Your server's public URL, set as the
FRONTEND_BASE_URLenvironment variable (for examplehttps://photos.example.com). This one is not optional. The reverse proxy in front of the backend rewrites theHostheader, so LibrePhotos genuinely cannot work out its own public address from an incoming request β it has to be told. Without it the login button reports that SSO is not fully configured. - An email provider configured in Site settings, if you want LibrePhotos to create accounts on first login. See the email settings page. Without email configured, LibrePhotos will not create accounts over SSO, because it has no way to act on the provider's claim that an address is verified.
Registering LibrePhotos with your identity providerβ
Create a confidential client (one with a client secret) at your provider and give it this redirect URI:
https://your-librephotos-url/api/accounts/oidc/<provider_id>/login/callback/
<provider_id> is a short name you choose in the next step β keycloak,
authentik, google, whatever you like. It must match exactly.
Note down the client ID, the client secret, and the provider's issuer URL (the
one whose /.well-known/openid-configuration document describes it).
Telling LibrePhotos about the providerβ
In the Django admin (/api/django-admin/), under Social applications, add one:
| Field | Value |
|---|---|
| Provider | OpenID Connect |
| Provider ID | the <provider_id> you used in the redirect URI |
| Name | what the login button should say, if you add more than one provider |
| Client id | from your provider |
| Secret key | from your provider |
| Settings | {"server_url": "https://your-idp/realms/example"} β the issuer URL |
| Sites | pick your site |
Then, in the app, open Admin area > Site settings and find the Single sign-on group. Each change saves at once. New in 1.5.0 Up to 1.4.0 these switches were only on the Constance page of the Django admin, under the names in brackets.
- Show the single sign-on button (
OIDC_ENABLED): the on/off switch. While it is off, the login button is hidden and the SSO endpoints are inactive, so switching it off is a real way to stop SSO logins. - Button label (
OIDC_BUTTON_LABEL): the text on the login button, e.g. "Sign in with Keycloak", at most 64 characters. With more than one provider each button shows its provider's name instead. - Allow sign-ups over single sign-on (
OIDC_ALLOW_SIGNUP): whether a first-time SSO login may create a new LibrePhotos account. Off by default; also requires email to be configured.
The provider itself is only added and changed in the Django admin, as above. The
group lists the providers it finds, and warns under the switches when SSO cannot
work yet: no provider attached to this site, no public URL
(FRONTEND_BASE_URL), or, for sign-ups, no email set up.
How accounts are matched upβ
On a first SSO login, LibrePhotos looks for an existing account whose email matches the one the provider reports:
- A single matching account, and the provider says the address is verified β the two are linked, and from then on the provider's stable user id identifies that person, as long as the account's address is trusted (see below).
- The matching account's address is not trusted β refused, and no new account is made for the address. Not released yet (comes after 1.7.0) Up to 1.7.0, any account with the address was linked, so someone who typed another person's address into their own profile got that person's SSO identity on its first login.
- The provider has not verified the address β refused. Otherwise anyone able to register your email address at the provider could claim your account.
- Two or more accounts share the address β refused, whether or not sign-ups over SSO are on, because there is no single right answer. LibrePhotos does not create yet another account with the same address either.
- The matching account is deactivated β refused, also when it was linked before, and no new account is made for its address. Turn the account back on to let it sign in. New in 1.7.0 Up to 1.6.0, a deactivated account was linked, and signed in as soon as it was turned back on.
- The provider sends no address β refused, since there is nothing to match on and no verified address to create an account with.
- No matching account β a new one is created only if
OIDC_ALLOW_SIGNUPis on and email is configured. Otherwise create the account first (or set its email to match) and let the user sign in again.
Accounts created through SSO are never administrators. Grant that in the admin afterwards if you want it.
Not released yet (comes after 1.7.0) An account created through SSO has no LibrePhotos password. To set one in Profile, or to change its e-mail address there, the user must have signed in within the last 10 minutes; otherwise LibrePhotos asks them to sign in again first. Accounts with a password confirm such a change with their current password instead.
Not released yet (comes after 1.7.0) Signing in again goes through the identity provider
the usual way. LibrePhotos sends the browser straight to the provider
(SOCIALACCOUNT_LOGIN_ON_GET) and does not ask it to show its login page again
(no prompt=login), so while the provider still has a session in that browser,
it signs the user back in without asking for anything. The 10-minute rule
therefore protects against a LibrePhotos token that was copied and is used
elsewhere, not against someone who sits down at a browser that is still signed
in to the provider. To close that gap too, have the provider ask for the
password again, or keep its sessions short.
Which addresses are trustedβ
Not released yet (comes after 1.7.0)An account's email address is trusted for SSO when:
- an admin set it: in the user editor (Admin area > Users), when creating the account (staff included), or in the Django admin;
- it is the first admin's own, given at first-time setup up to 1.7.0, or with
adminEmailin Docker; - the account was created by an SSO login, or an earlier SSO login of the same account reported that address as verified.
An address a user types into their own Profile is not trusted until one of these happens, and any change of the address in the profile, even of its case, takes the trust away. Sign-ups other than the first admin's are not trusted either. The first-time setup no longer asks for an address: to connect the first admin to SSO, set the address in the Django admin. To vouch for an address a user typed, an admin changes it in the user editor: an admin saving the dialog with the address the user typed unchanged does not trust it, so clear it, save, enter it again and save.
Addresses match when they are equal apart from the case of the letters A to Z.
Other letters must be the same: straΓe@ and strasse@ are different
addresses, and so are a dotless Δ± and an i.
Updating to 1.8.0 decides the trust of the addresses accounts already have, depending on Allow user registration (Admin area > Site settings) at the moment of the update:
- Off (the default): every existing address is trusted. Only admins could create accounts, so the addresses are the ones they gave or the users typed into their own profiles, as in a family install. Nothing changes for SSO.
- On: anyone could have signed up and typed any address, so LibrePhotos trusts only the addresses of admins (staff and superusers) and the ones an identity provider already reported as verified for that account. Every other existing address is not trusted, also on accounts an admin created, and its first SSO login is refused until it becomes trusted: an admin sets it again in the user editor as described above, or, for an account already linked to a provider, an SSO login reports the address as verified.
Accounts already linked to a provider keep signing in either way.
Using LDAP accountsβ
LibrePhotos does not connect to an LDAP directory itself. Instead, point your identity provider at the directory and LibrePhotos at the provider: people then log in with their directory username and password at the provider, and LibrePhotos gets the result over OpenID Connect. Every common self-hosted provider can do this.
- Authelia: set up the LDAP authentication backend (it works with LLDAP, OpenLDAP and Active Directory), then add LibrePhotos as an OpenID Connect client.
- Authentik: add an LDAP source that syncs your directory, then an OAuth2/OpenID provider with an application for LibrePhotos.
- Keycloak: in your realm, add User Federation with an LDAP provider, then a confidential OpenID Connect client. Turn on Trust Email on the LDAP provider, or Keycloak reports directory addresses as unverified and LibrePhotos refuses them.
What this means for accounts: LibrePhotos matches people by the email address the directory holds, and only when the provider says it is verified (see How accounts are matched up). Either give each LibrePhotos account the same email as in the directory, or turn on sign-ups over SSO so that a first login creates the account.
The mobile app logs in with a username and password, not with SSO. A user who only ever signed in through the provider has no LibrePhotos password yet; they can set one with Forgot password? on the login page (this needs email to be configured).
When something goes wrongβ
A failed attempt returns to the login page with an explanation. The usual causes:
| Message | What to change |
|---|---|
| That account is not known to LibrePhotos. Ask an administrator to create it, or to allow sign-ups over SSO. | Create the account, or turn on OIDC_ALLOW_SIGNUP |
| Your identity provider has not verified that email address, so it cannot be used to sign in. | Verify the address at your identity provider |
| More than one LibrePhotos account uses this email address. Ask an administrator to fix it. | Give each LibrePhotos account its own email address (or clear it on the ones that should not log in over SSO) |
| The LibrePhotos account with this email address has not been confirmed for single sign-on. Ask an administrator to set the address in the user editor. | Set the address in the user editor as an admin (see Which addresses are trusted) |
| Sign-in was cancelled at your identity provider. | Nothing to fix: the user pressed Cancel or declined access. Try again |
| Your identity provider could not complete the sign-in. Check the server logs for details. | Look in the server log for the line starting SSO login via; it names the reason (for example an expired login, or the provider refusing the client secret) |
| This LibrePhotos account is turned off. Ask an administrator to turn it back on. | The matching account is deactivated: turn it back on |
| Single sign-on is not fully configured: the administrator needs to set this server's public URL (FRONTEND_BASE_URL). | Set FRONTEND_BASE_URL |
| Provider-side "invalid redirect URI" | The redirect URI at your provider must match the callback URL above exactly, including the trailing slash |