Skip to content

Nextcloud

Nextcloud uses OkYouIn as its SAML 2.0 identity provider through the SSO & SAML authentication app (user_saml). Users sign in on OkYouIn’s page with their password and second factor and land in Nextcloud. For OkYouIn’s SAML IdP in general, see SAML 2.0.

ProductVersionModesWhat was verified
Nextcloud (Docker image nextcloud:34.0.5-apache), user_saml 8.5.034.0.5password + MFASign-in with TOTP (local and Active Directory users); single sign-on into GitLab without a prompt; MFA asked again after the session lifetime; policy deny; single logout with OkYouIn confirmation; groups as SAML_<group>; signing Response and assertion; certificate rotation
  • Second factor: TOTP was verified. Push and e-mail MFA were not tested with Nextcloud.
  • Users and groups: the user ID, display name, e-mail and groups come from OkYouIn at every sign-in.
  • Not supported: IdP-initiated sign-in (user_saml needs its own request) — keep IdP-initiated sign-in off. Making a SAML user a Nextcloud admin through a group is not possible (see below).
  • Nextcloud must be served over HTTPS. OkYouIn posts the SAML Response only to an https ACS URL.
  • OkYouIn’s public URL (Settings ▸ General) must be an https:// address.
  • Create the application in Access ▸ Applications ▸ Add application ▸ Nextcloud. The template sends uid (username), email, displayName and groups (multi-valued), NameID format Unspecified with the username as NameID value, signed with the global certificate.
  • The application’s SAML slug — nextcloud in the examples — is part of every IdP URL. The Connect tab shows the commands with your real slug and host.
  1. Register Nextcloud in OkYouIn. The easiest way is to import its SP metadata: open https://cloud.example.com/apps/user_saml/saml/metadata?idp=1 in a browser, save it, and use Import SP metadata on the application’s Settings tab. Or enter the values by hand:

    SettingValue
    SP Entity IDhttps://cloud.example.com/apps/user_saml/saml/metadata
    ACS endpointshttps://cloud.example.com/apps/user_saml/saml/acs
    SP single logout URLhttps://cloud.example.com/apps/user_saml/saml/sls, binding HTTP-Redirect

    Use the URLs as the browser sees them. occ saml:metadata prints /index.php/ URLs, which do not match the requests of a Nextcloud with pretty URLs.

  2. Install and configure user_saml with occ, run as the web server user (provider 1 on a fresh install). The IdP certificate is read straight from OkYouIn:

    Terminal window
    occ() { sudo -u www-data php /var/www/html/occ "$@"; }
    occ app:install user_saml
    occ config:app:set user_saml type --value=saml
    occ saml:config:create
    occ saml:config:set 1 \
    --general-idp0_display_name="OkYouIn" \
    --general-uid_mapping=uid \
    --idp-entityId="https://mfa.example.com/saml/nextcloud" \
    --idp-singleSignOnService.url="https://mfa.example.com/saml/nextcloud/sso" \
    --idp-singleLogoutService.url="https://mfa.example.com/saml/nextcloud/slo" \
    --idp-x509cert="$(curl -fsS https://mfa.example.com/saml/nextcloud/certificate.pem)" \
    --saml-attribute-mapping-email_mapping=email \
    --saml-attribute-mapping-displayName_mapping=displayName \
    --saml-attribute-mapping-group_mapping=groups \
    --sp-name-id-format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" \
    --security-wantAssertionsSigned=1 \
    --security-wantMessagesSigned=1
  3. Allow the application in the policy.

  • The uid attribute (the OkYouIn username) is the Nextcloud user ID. Display name and e-mail are updated at every sign-in.
  • Groups arrive as SAML_<group> (user_saml’s group mapping prefix). Use Groups filter on the application to limit which groups are sent.
  • user_saml never puts a SAML user into Nextcloud’s admin group. Grant administration in Nextcloud (admin delegation) to a SAML_ group instead.

Keep Sign at Response and assertion together with wantMessagesSigned=1 and wantAssertionsSigned=1. Nextcloud refuses a Response that lacks a signature it wants, with “Account not provisioned”. The other two signing modes work only with the matching want… flag turned off.

Nextcloud holds exactly one IdP certificate and does not read metadata. After Activate next in OkYouIn, sign-ins fail until Nextcloud has the new certificate, so run the --idp-x509cert line again right after activating:

Terminal window
occ saml:config:set 1 --idp-x509cert="$(curl -fsS https://mfa.example.com/saml/nextcloud/certificate.pem)"

To keep a rotation of the global certificate from touching Nextcloud, switch the application to its own certificate (Signing certificate ▸ Own certificate) and rotate it when it suits you.

Nextcloud’s Log out sends a LogoutRequest. OkYouIn asks “Sign out?” (the request is unsigned), ends its session and returns to Nextcloud. Other applications of the same SSO session stay signed in — OkYouIn does not propagate a logout to them. Revoking a session in Logging ▸ SSO sessions makes the next sign-in ask for the password, but does not end a Nextcloud session that is already open.

  1. In a private window, open Nextcloud and choose OkYouIn; sign in with password and code.
  2. In Nextcloud, check the user’s display name, e-mail and SAML_ groups.
  3. Logging ▸ SSO sign-in log shows the SAML sign-in with the MFA round and the allow.
  4. Preview for a user on the application shows the NameID and attributes a user would get, without signing in.
SymptomCause
”Account not provisioned”Nextcloud’s message for every refused Response: a missing signature it wants, a policy deny, or a certificate mismatch. Check the SSO sign-in log first.
OkYouIn refuses the request (bad request, issuer)The SP Entity ID in OkYouIn has /index.php/ while Nextcloud sends the pretty URL, or the other way round. Import the metadata from the browser URL.
Sign-ins fail right after a rotationNextcloud still holds the old certificate. Re-run the --idp-x509cert line.
IdP-initiated sign-in lands on the login pageNot supported by user_saml. Turn IdP-initiated sign-in off.