Integrate with Nextcloud
Support level: Community
What is Nextcloud
Nextcloud is a suite of client-server software for creating and using file hosting services. Nextcloud is free and open-source, which means that anyone is allowed to install and operate it on their own private server devices.
If you require server side encryption, you must use LDAP. OpenID and SAML will cause irrevocable data loss. Nextcloud server side encryption requires access to the user's cleartext password, which Nextcloud has access to only when using LDAP because the user enters their password directly into Nextcloud.
This setup only works when Nextcloud is running with HTTPS enabled. See here on how to configure this.
If there’s an issue with the configuration, you can log in using the built-in authentication by visiting http://nextcloud.company/login?direct=1.
Configuration methods
It is possible to configure Nextcloud to use OIDC, SAML, or LDAP for authentication. Below are the steps to configure each method.
- OIDC
- SAML
- LDAP
Preparation
The following placeholders are used in this guide:
nextcloud.company
is the FQDN of the Nextcloud installation.authentik.company
is the FQDN of the authentik installation.
This documentation lists only the settings that you need to change from their default values. Be aware that any changes other than those explicitly mentioned in this guide could cause issues accessing your application.
If you require server side encryption, you must use LDAP. OpenID and SAML will cause irrevocable data loss.
Let's start by considering which user attributes need to be available in Nextcloud:
- name
- unique user ID
- storage quota (optional)
- groups (optional)
authentik already provides some default scopes with claims, such as:
email
scope: includesemail
andemail_verified
profile
scope: includesname
,given_name
,preferred_username
,nickname
,groups
openid
scope: a default required by the OpenID spec (contains no claims)
Create property mapping (optional)
If you do not need storage quota, group information, or to manage already existing users in Nextcloud, skip to the next section.
If you want to control user storage and designate Nextcloud administrators, you will need to create a property mapping.
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Customization > Property mappings and click Create.
-
Select type: select Scope mapping.
-
Create Scope Mapping:
-
Name:
Nextcloud Profile
-
Scope name:
nextcloud
-
Expression:
# Extract all groups the user is a member of
groups = [group.name for group in user.ak_groups.all()]
# In Nextcloud, administrators must be members of a fixed group called "admin".
# If a user is an admin in authentik, ensure that "admin" is appended to their group list.
if user.is_superuser and "admin" not in groups:
groups.append("admin")
return {
"name": request.user.name,
"groups": groups,
# Set a quota by using the "nextcloud_quota" property in the user's attributes
"quota": user.group_attributes().get("nextcloud_quota", None),
# To connect an existing Nextcloud user, set "nextcloud_user_id" to the Nextcloud username.
"user_id": user.attributes.get("nextcloud_user_id", str(user.uuid)),
}
-
-
-
Click Finish.
To set a quota, define the nextcloud_quota
attribute for individual users or groups. For example, setting it to 1 GB
will restrict the user to 1GB of storage. If not set, storage is unlimited.
To connect to an existing Nextcloud user, set the nextcloud_user_id
attribute to match the Nextcloud username (found under the user's Display name
in Nextcloud).
Create an application and provider in authentik
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Applications > Applications and click Create with Provider to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
- Application: provide a descriptive name, an optional group for the type of application, the policy engine mode, and optional UI settings.
- Choose a Provider type: select OAuth2/OpenID Connect as the provider type.
- Configure the Provider: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations.
- Note the Client ID and slug values because they will be required later.
- Set a
Strict
redirect URI tohttps://nextcloud.company/apps/user_oidc/code
. - Select any available signing key.
- Under Advanced Protocol Settings:
- (optional) If you created the
Nextcloud Profile
scope mapping, add it to Selected Scopes. - Subject Mode:
Based on the User's UUID
- (optional) If you created the
- Configure Bindings (optional): you can create a binding (policy, group, or user) to manage the listing and access to applications on a user's My applications page.
-
Click Submit to save the new application and provider.
Depending on your Nextcloud configuration, you may need to use https://nextcloud.company/index.php/
instead of https://nextcloud.company/
.
Nextcloud configuration
-
In Nextcloud, ensure that the OpenID Connect user backend app is installed.
-
Log in to Nextcloud as an administrator and navigate to Settings > OpenID Connect.
-
Click the + button and enter the following settings:
-
Identifier:
authentik
-
Client ID: Client ID from authentik
-
Client secret: Client secret from authentik
-
Discovery endpoint:
https://authentik.company/application/o/<application_slug>/.well-known/openid-configuration
-
Scope:
email nextcloud openid
-
Under Attribute mappings:
-
User ID mapping:
sub
(oruser_id
for existing users) -
Display name mapping:
name
-
Email mapping:
email
-
Quota mapping:
quota
(leave blank if theNextcloud Profile
property mapping was skipped) -
Groups mapping:
groups
(leave blank if theNextcloud Profile
property mapping was skipped)tipEnable Use group provisioning to allow writing to this field.
-
-
Use unique user ID: If this option is disabled, Nextcloud will use the mapped user ID as the Federated Cloud ID.
noteIf authentik and Nextcloud are running on the same host, you will need to add
'allow_local_remote_servers' => true
to your nextcloudconfig.php
file. This setting allows remote servers with local addresses.tipTo avoid a hashed Federated Cloud ID, deselect Use unique user ID and use
user_id
for the User ID mapping.dangerIf you're using the
Nextcloud Profile
property mapping and want administrators to retain their ability to log in, make sure that Use unique user ID is disabled. If this setting is enabled, it will remove administrator users from the internal admin group and replace them with a hashed group ID named "admin," which does not have real administrative privileges. -
Making OIDC the default login method
Automatically redirect users to authentik when they access Nextcloud by running the following command on your Nextcloud docker host:
sudo docker exec --user www-data -it nextcloud-aio-nextcloud php occ config:app:set --value=0 user_oidc allow_multiple_user_backends
Configuration verification
To confirm that authentik is correctly configured with Nextcloud, log out and then log back in by clicking OpenID Connect. You'll then be redirected to authentik to log in, and once authentication is successful, you'll reach the Nextcloud dashboard.
Preparation
The following placeholders are used in this guide:
nextcloud.company
is the FQDN of the Nextcloud installation.authentik.company
is the FQDN of the authentik installation.
This documentation lists only the settings that you need to change from their default values. Be aware that any changes other than those explicitly mentioned in this guide could cause issues accessing your application.
If you require server side encryption, you must use LDAP. OpenID and SAML will cause irrevocable data loss.
Create an application and provider in authentik
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Applications > Applications and click Create with Provider to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
- Application: provide a descriptive name, an optional group for the type of application, the policy engine mode, and optional UI settings.
- Note the application slug because it will be required later.
- Choose a Provider type: select SAML Provider as the provider type.
- Configure the Provider: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations.
- Set the ACS URL to
https://nextcloud.company/apps/user_saml/saml/acs
. - Set the Issuer to
https://authentik.company
. - Set the Audience to
https://nextcloud.company/apps/user_saml/saml/metadata
. - Set the Service Provider Binding to
Post
. - Under Advanced protocol settings, set an available signing certificate.
- Set the ACS URL to
- Configure Bindings (optional): you can create a binding (policy, group, or user) to manage the listing and access to applications on a user's My applications page.
- Application: provide a descriptive name, an optional group for the type of application, the policy engine mode, and optional UI settings.
-
Click Submit to save the new application and provider.
Depending on your Nextcloud configuration, you might need to use https://nextcloud.company/index.php/
instead of https://nextcloud.company/
.
Download the signing certificate
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to Applications > Providers and click on the name of the newly created Nextcloud provider.
- Under Download signing certificate click Download. The contents of this certificate will be required in the next section.
Configure group quotas (optional)
To configure group quotas you will need to create groups in authentik for each quota, and a property mapping.
Create group/s in authentik (optional)
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to Directory > Groups and click Create.
- Set a name for the group (e.g.
nextlcloud-15GB
), assign a custom attribute (e.g.,nextcloud_quota
), and click Create. - Click the name of the newly created group and navigate to the Users tab.
- Click Add existing user, select the users that require this storage quota and click Add.
Create property mapping in authentik (optional)
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Customization > Property mappings and click Create.
-
Select type: select SAML Provider Property Mapping as the property mapping type.
-
Create SAML Provider Property Mapping:
-
Name: Provide a name for the property mapping.
-
SAML Attribute Name:
nextcloud_quota
-
Expression:
return user.group_attributes().get("nextcloud_quota", "1 GB")
noteWhere
"1 GB"
is the default if a quota is not set.
-
-
-
Click Finish to save the property mapping.
Configure quota attribute in Nextcloud (optional)
- Log in to Nextcloud as an administrator.
- Navigate to Settings > SSO & SAML Authentication.
- Set Attribute to map the quota to to
nextcloud_quota
.
Configure admin group (optional)
To grant Nextcloud admin access to authentik users you will need to create a property mapping.
Create property mapping in authentik (optional)
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Customization > Property mappings and click Create.
-
Select type: select SAML Provider Property Mapping as the property mapping type.
-
Create SAML Provider Property Mapping:
-
Name: Provide a name for the property mapping.
-
SAML Attribute Name:
http://schemas.xmlsoap.org/claims/Group
-
Expression:
for group in request.user.all_groups():
yield group.name
if ak_is_group_member(request.user, name="<authentik nextcloud admin group's name>"):
yield "admin"
-
-
Configure group attribute in Nextcloud (optional)
- Log in to Nextcloud as an administrator.
- Navigate to Settings > SSO & SAML Authentication.
- Set the groups mapping to
http://schemas.xmlsoap.org/claims/Group
.
Nextcloud configuration
-
In Nextcloud, ensure that the SSO & SAML Authentication app is installed.
-
Log in to Nextcloud as an administrator, navigate to Settings > SSO & SAML Authentication, and configure the following settings:
- Attribute to map the UID to:
http://schemas.goauthentik.io/2021/02/saml/uid
dangerUsing the UID attribute as username is not recommended because of its mutable nature. If you map to the username instead, disable username changing and set the UID attribute to
http://schemas.goauthentik.io/2021/02/saml/username
.- Optional display name:
authentik
- Identifier of the IdP entity:
https://authentik.company
- URL target for authentication requests:
https://authentik.company/application/saml/<application_slug>/sso/binding/redirect/
- URL for SLO requests:
https://authentik.company/application/saml/<application_slug>/slo/binding/redirect/
- Public X.509 certificate of the IdP: Paste the contents of your certificate file.
- Set attribute mappings:
- Display name:
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
- Email:
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
- User groups:
http://schemas.xmlsoap.org/claims/Group
- Display name:
- Attribute to map the UID to:
If Nextcloud is behind a reverse proxy, force HTTPS by adding 'overwriteprotocol' => 'https'
to the Nextcloud config/config.php
file. See this guide for more details.
Configuration verification
To confirm that authentik is properly configured with Nextcloud, log out and log back in using the SSO and SAML log in option. You will be redirected to authentik to log in; if successful you will then be redirected to the Nextcloud dashboard.
Preparation
The following placeholders are used in this guide:
nextcloud.company
is the FQDN of the Nextcloud installation.authentik.company
is the FQDN of the authentik installation.
This documentation lists only the settings that you need to change from their default values. Be aware that any changes other than those explicitly mentioned in this guide could cause issues accessing your application.
Create an application and provider in authentik
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Applications > Applications and click Create with Provider to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
- Application: provide a descriptive name, an optional group for the type of application, the policy engine mode, and optional UI settings.
- Choose a Provider type: select LDAP as the provider type.
- Configure the Provider: provide a name (or accept the auto-provided name) and the bind flow to use for this provider
- Configure Bindings (optional): you can create a binding (policy, group, or user) to manage the listing and access to applications on a user's My applications page.
-
Click Submit to save the new application and provider.
Create an LDAP outpost
-
Log in to authentik as an admin, and open the authentik Admin interface.
-
Navigate to Applications > Outposts and click Create.
- Name: provide a suitable name for the outpost.
- Type:
LDAP
- Under applications, add the newly created Nextcloud application to Selected Applications.
-
Click Create.
Nextcloud configuration
-
In Nextcloud, ensure that the LDAP user and group backend app is installed.
-
Log in to Nextcloud as an administrator.
-
Navigate to Settings > LDAP user and group backend and configure the following settings:
-
On the Server tab:
- Click the + icon and enter the following settings:
- Host: enter the hostname/IP address of the authentik LDAP outpost preceded by
ldap://
orldaps://
. If using LDAPS you will also need to specify the certificate that is being used. - Port:
389
or636
for secure LDAP. - Under Credentials, enter the Bind DN of the authentik LDAP provider and the associated user password.
- Under Base DN, enter the Search base of the authentik LDAP provider.
- Host: enter the hostname/IP address of the authentik LDAP outpost preceded by
- Click the + icon and enter the following settings:
-
On the Users tab:
- Set Only these object classes to
Users
.
- Set Only these object classes to
-
On the LDAP/AD integration tab:
- Uncheck LDAP/AD Username.
- Set Other Attributes to
cn
. - Click Expert in the top right corner and enter these settings:
- Internal Username Attribute:
uid
- UUID Attribute for Users:
uid
- UUID Attribute for Groups:
gidNumber
- Internal Username Attribute:
- Click Advanced in the top right corner and enter these settings:
- Under Connection Settings:
- Configuration Active: checked
- Under Directory Settings:
- User Display Name Field:
name
- Base User Tree: enter the Search base of the authentik LDAP provider.
- Group Display Name Field:
cn
- Base Group Tree: enter the Search base of the authentik LDAP provider.
- Group-Member Association:
gidNumber
- User Display Name Field:
- Under Special Attributes:
- Email Field:
mailPrimaryAddress
- Email Field:
- Under Connection Settings:
-
On the Groups tab:
- Set Only these object classes to
groups
. - Select the authentik groups that require Nextcloud access.
- Set Only these object classes to
noteIf Nextcloud is behind a reverse proxy, force HTTPS by adding
'overwriteprotocol' => 'https'
to the Nextcloudconfig/config.php
file. See the Nextcloud admin manual for more details. -
Configuration verification
To confirm that authentik is properly configured with Nextcloud, log out and log back in using LDAP credentials. If successful you will then be redirected to the Nextcloud dashboard.