Protect your Nextcloud logins with a second factor that you control. This app connects the Nextcloud login to your own privacyIDEA server. Nextcloud asks for the second factor, and privacyIDEA checks it.
privacyIDEA is an open-source authentication server. It manages the second factors of all your users in one place, with policies, an audit log and a self-service portal. The same server can also protect other logins, for example Windows, VPN (through RADIUS) or Keycloak. Nextcloud stores no token secrets.
- Passkeys and FIDO2 security keys (WebAuthn), for example a YubiKey, Windows Hello or the passkey on a phone.
- Push notifications: the user confirms the login with one tap in the privacyIDEA Authenticator app.
- One-time passwords (OTP) from any TOTP or HOTP app, for example Google Authenticator, Microsoft Authenticator or FreeOTP, or from a hardware token.
- Codes by email or SMS.
If a user has more than one type of token, the login page lets the user switch between them.
- Enrollment at login: privacyIDEA can ask a user without a token to enroll one on the login page. The user scans a QR code (OTP app or smartphone container) or registers a passkey. If your policy allows it, the user can skip this step.
- Login flows: trigger all challenges before the login page shows, so that the push or SMS is already on its way. You can also send the Nextcloud password or a fixed password to privacyIDEA first.
- Who must use MFA: include or exclude Nextcloud groups, and exclude IPv4 addresses or ranges.
- Rules in one place: token types, lockout and other policies stay in privacyIDEA.
- Nextcloud 29 to 35, PHP 8.3 or newer.
- A privacyIDEA server that your Nextcloud server can reach.
- Download the
.tar.gzarchive of the latest release. - Unpack it into the apps folder of Nextcloud:
tar -xzf privacyidea-*.tar.gz -C <nextcloud>/apps/. If your installation has a separate folder for added apps, use that folder. For example, the official Docker image usescustom_apps/. - Enable the app. In Nextcloud, open Apps → Disabled apps and click
Enable next to privacyIDEA. Or run
sudo -u www-data php occ app:enable privacyidea.
The app has no build step, so a copy of the repository works as it is.
- Clone or copy this repository to
<nextcloud>/apps/privacyidea. - Enable the app as in step 3 above.
All settings live in Nextcloud under Settings → Administration → privacyIDEA
(or scriptable via occ config:app:set privacyidea <key> --value=<value>). At a
minimum, set the server URL and tick Activate privacyIDEA.
| Setting | Key | Description |
|---|---|---|
| Activate privacyIDEA | piActivatePI |
Master switch for MFA via privacyIDEA. Configure the server connection before enabling. |
| URL of the privacyIDEA server | piURL |
Base URL of your privacyIDEA instance, e.g. https://pi.example.com. |
| SSL certificate verification | piSSLVerify |
Verify the server's TLS certificate (host and peer). Keep enabled in production. |
| Realm | piRealm |
privacyIDEA realm to authenticate against, if not the default. |
| Timeout | piTimeout |
Request timeout in seconds (default 15; connection setup is capped at 5s). Prevents an unresponsive server from hanging the login page. |
| No proxy | piNoProxy |
Ignore the system-wide proxy and talk to privacyIDEA directly. |
| Forward client IP | piForwardClientIP |
Send the user's IP as the client parameter so privacyIDEA policies can match on the original address. Make sure to add the IP address of the Nextcloud Server to the Override Authorization Clients list in the privacyIDEA Server System config, to log the actual user's IP address. |
| Setting | Key | Description |
|---|---|---|
| Exclude IP addresses | piExcludeIPs |
Skip MFA for these IPv4 addresses/ranges, e.g. 10.0.1.12,10.0.1.20-10.0.1.40. (IPv4 only; non-IPv4 or unparseable entries are ignored and never skip MFA.) |
| Group names + Include/Exclude | piInExGroupsField, piInOrExSelected |
Restrict MFA to (Include) or skip it for (Exclude) members of the listed Nextcloud groups (comma-separated). |
Exclude IP addresses and Forward client IP use the client address that
Nextcloud sees. Behind a reverse proxy, set trusted_proxies in the Nextcloud
config.php (see
Reverse proxy configuration).
Otherwise Nextcloud sees the address of the proxy for every request. If an
excluded range contains that address, no user has to use MFA.
The Authentication flow radios (piSelectedAuthFlow) control what is sent to
privacyIDEA before the login screen is shown — used to trigger the user's token
challenges (or complete authentication) up front. Mutually exclusive:
| Flow (setting value) | What happens | Extra settings |
|---|---|---|
None (prompt only) — default (piAuthFlowDefault) |
Nothing is sent up front; the login screen is shown and whatever the user submits goes to /validate/check. Any challenges the server returns are then shown. |
— |
Trigger Challenge (piAuthFlowTriggerChallenge) |
On page load the app uses a service account to call /validate/triggerchallenge for the user, so all of the user's challenges (push, SMS, email, …) are triggered up front. |
Service name + Service password (Service realm optional). |
Send Password (piAuthFlowSendPassword) |
On page load the app sends the user's Nextcloud login password to /validate/check — completing login (e.g. passthru) or triggering challenges. Password logins only; for SSO/passkey/token logins it falls back to prompting. |
— |
Send Static Pass (piAuthFlowSendStaticPass) |
On page load the app sends a fixed configured password to /validate/check — completing login (e.g. passOnNoToken) or triggering challenges. |
Static password. |
The input layout on the login screen (single OTP field, or a separate password/PIN field plus OTP) is a separate Login screen setting — see below.
| Setting | Key | Description |
|---|---|---|
| Input layout | piInputLayout |
Login-screen layout: a single OTP field (otp, default) or a separate password/PIN field plus an OTP field (separate), combined and sent to privacyIDEA. |
| OTP field hint | piOTPFieldHint |
Placeholder text shown in the OTP input field (default "One-Time-Password"). |
| Password/PIN field hint | piPassFieldHint |
Placeholder text shown in the Password/PIN field of the separate layout (default "Password/PIN"). |
| Auto-submit by OTP length | piActivateAutoSubmitOtpLength, piAutoSubmitOtpLength |
Submit the form automatically once the configured number of characters (default 6) is entered in the OTP field. |
| Poll in browser | piPollInBrowser, piPollInBrowserURL |
For PUSH tokens, poll privacyIDEA directly from the browser so the page advances the moment the user confirms, instead of periodic page reloads. Requires a privacyIDEA URL reachable from the browser. |
| Forward headers to privacyIDEA | piForwardHeaders |
Comma-separated list of request header names to forward to privacyIDEA (useful for header-based policies). |
Turn on Poll in browser for push tokens. Without it, the login page reloads to ask whether the user confirmed the push: at once, then after 8, 5 and 4 seconds, and then every 4 seconds. Each reload is a request to the two-factor endpoint of Nextcloud. By default, Nextcloud accepts 5 of these requests per user in 100 seconds. If the user takes longer than about 20 seconds, Nextcloud answers "Too many requests".
With Poll in browser, the browser asks privacyIDEA directly, at the URL in
piPollInBrowserURL. If privacyIDEA has a different origin than Nextcloud (a
different scheme, host or port), the browser needs CORS headers. privacyIDEA
does not send them. Add them on the web server or reverse proxy in front of
privacyIDEA, for the path /validate/polltransaction:
Access-Control-Allow-Origin: https://cloud.example.com
Without this header, the browser blocks the poll requests. The login page then falls back to reloads, with the limit described above.
- The app writes its messages to the Nextcloud log. At log level debug, it also
logs every request to privacyIDEA and the response. Passwords show as
REDACTED. To set the level, runsudo -u www-data php occ log:manage --level=debug. Afterwards, set it back with--level=warning. - If users who logged in before do not get the MFA prompt, see Enforce MFA for already-logged-in users.
- If Poll in browser does not work, open the developer console of the browser on the login page. A CORS error means that the header from Push tokens is missing.
Go to your Nextcloud installation directory and run one of the following commands:
sudo -u www-data php occ app:enable privacyideasudo -u www-data php occ app:disable privacyidea
Nextcloud evaluates whether MFA applies to a user only once and caches the result in its two-factor provider registry, so enabling or reconfiguring the app does not retroactively affect users who are already logged in. To force Nextcloud to re-evaluate this on the next login, clear the cached state:
sudo -u www-data php occ twofactorauth:cleanup privacyidea
Existing sessions that already passed login are not challenged retroactively; the re-evaluation happens the next time the affected users log in.
A throwaway Nextcloud for testing the app is provided via Docker Compose. It
runs on SQLite (no separate database), auto-installs on first boot, and
bind-mounts this repository as the privacyidea app (auto-enabled), so your
changes are live without a rebuild. You still need your own reachable
privacyIDEA server; set its URL in the admin settings after logging in.
docker compose -f docker-compose.dev.yml up -d # start (Nextcloud "stable")
NC_VERSION=latest docker compose -f docker-compose.dev.yml up -d # test the newest release
docker compose -f docker-compose.dev.yml down -v # stop and wipeThen open http://localhost:8080 and log in as admin / admin. The Nextcloud
version is just the NC_VERSION image tag. See dev/README.md
for details (version switching, running occ, logs).
The PHP test suite and static analysis run via Composer:
composer install
composer run lint # php -l
composer run cs:check # coding standard (composer run cs:fix to apply)
composer run psalm # static analysis
composer run test:unit # PHPUnittests/e2e/run.sh tests the app in a real Nextcloud. It starts a throwaway
Nextcloud container, installs the app from your working tree and points it at a
mock privacyIDEA. Then headless Chrome logs in with a password and an OTP and
changes a value on the admin settings page. After a logout, it logs in again
with a push token while Poll in browser is on. At the end, the script checks
the Nextcloud log for errors from the app.
tests/e2e/run.sh 35 # any Nextcloud Docker image tag, default: latestYou need Docker, Python 3, Node.js 22 or newer and Chrome or Chromium. The
GitHub workflow e2e.yml runs the same script on every pull request and push to
main. Every night, nextcloud-version-watch.yml looks for a new Nextcloud
major version. If it finds one, it runs psalm and this test against the new
version and opens an issue with the results.