loader image
View Categories

How to Use SAML/SSO or Single Sign On with Nextcloud and Auth0

SAML (Security Assertion Markup Language) is an open standard for exchanging authentication and authorization data between parties, particularly between an identity provider (IdP) and a service provider (SP). It is widely used for Single Sign-On (SSO), enabling users to authenticate once and gain access to multiple applications without having to log in again.

Here’s how SAML works:

  1. User Requests Access: A user attempts to access a service provider (SP) application, such as a web app or cloud service.

  2. Redirect to Identity Provider (IdP): The service provider checks if the user is authenticated. If not, the user is redirected to an identity provider (IdP) like Google, Okta, or Active Directory.

  3. Authentication at IdP: The user authenticates with the IdP, usually with a username and password. The IdP may also use multi-factor authentication (MFA) for added security.

  4. SAML Assertion: After authentication, the IdP generates a SAML Assertion—an XML document containing the user’s authentication information and authorization details. This assertion is signed by the IdP to ensure its authenticity.

  5. Assertion Sent to SP: The SAML assertion is sent back to the service provider (SP), typically via the user’s browser. This step is usually done via HTTP POST.

  6. Verification and Access: The service provider verifies the authenticity of the SAML assertion, ensuring it’s from a trusted IdP. Once verified, the user is granted access to the requested resource.

Key Benefits of SAML Authentication #

  • Single Sign-On (SSO): Users authenticate once with an IdP and can access multiple applications without needing to log in again.
  • Improved Security: Credentials are only stored and managed by the IdP, reducing the risk of password theft at the SP level. The use of signed SAML assertions also ensures secure transmission of authentication data.
  • Centralized User Management: Administrators can manage user identities centrally through the IdP, simplifying user provisioning, de-provisioning, and access control across applications.
  • Reduced Password Fatigue: By reducing the need for multiple passwords, SAML enhances user experience and encourages better security practices.

Common Use Cases #

  • Enterprise Applications: SAML is frequently used by large organizations to enable employees to authenticate across multiple internal and external applications with a single login.
  • Cloud Service Access: Cloud-based platforms like AWS, GCP, and Salesforce support SAML authentication to allow users to access services with SSO.
  • Education and Government: SAML is commonly used for Federated Identity Management in academic institutions and government agencies to provide SSO across various systems.

Overall, SAML is a highly secure and efficient method for handling authentication and authorization in environments where centralized user management is crucial.

Variable Used:

<nextcloud_server_url>: https://nextcloud.domain.com/index.php 

<nextcloud_server_url>: https://nextcloud.domain.com/ [If index.php is disabled]

<ssl_crt>: It can be any SSL certificate or self-generated Certificate.
Note: for formatting instructions, you start with a PEM format certificate and replace the line endings with “\n”

<private_key>: The only private key of which the SSL is used or the self-generated Certificate.

<client_id>: The Client ID which is available in the Basic Information of Settings of the Application.

SSL Certificate Format
Auth0 Client ID

1. Follow the below configuration to add it in your Auth0 #

Beautiful Graphical Table

Auth0 Configuration #

SAML Protocol Description
ACS URL <nextcloud_server_url>/apps/user_saml/saml/acs
"audience" <nextcloud_server_url>/apps/user_saml/saml/metadata
"recipient" <nextcloud_server_url>/apps/user_saml/saml/acs
"nameIdentifierFormat" urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
"logout": "callback" <nextcloud_server_url>/apps/user_saml/saml/sls
"logout": "slo_enabled" true
"binding" urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect
"signResponse" false
"signatureAlgorithm" rsa-sha256
"signingCert" <ssl_crt>

To also enable Encrypt Assertation with the signing of SAML with the below code in Action. To enable follow: Action > Library > Custom Action.

Use Trigger: Login / Post Login

Auth0 Action
Code Copy Box

Encryption Code #

Copied exports.onExecutePostLogin = async (event, api) => { // this Action sets a specific public key to encrypt the SAML assertion generated from Auth0 if ( event.client.client_id === "<client_id>" ) { const encryptionCert = "<ssl_crt>"; const encryptionPublicKey = "<private_key>"; api.samlResponse.setEncryptionCert(encryptionCert); api.samlResponse.setEncryptionPublicKey(encryptionPublicKey); } };

2. Follow the below configuration to add it in your Nextcloud #

Beautiful Graphical Table

Nextcloud Configuration #

SAML Global Settings Description
Attribute to map the UID to username
Optional display name
of the identity provider
Auth0
X.509 certificate of
the Service Provider
<ssl_crt>
Private key of
the Service Provider
<private_key>
Identifier of the IdP
entity (must be a URI)
or Entity ID
urn:<tenantname.region.auth0.com>
URL Target of the IdP
where the SP will send
the Authentication Request
Message or
SingleSignOnService
<tenant.region.auth0.com>/samlp/<client_id>
URL Location of the
IdP where the SP
will send the SLO Request
or SingleLogoutService
<tenant.region.auth0.com>/samlp/<client_id>/logout
URL Location of the
IDP's SLO Response
Same as above SLO URL
Public X.509 certificate of
the IdP
The Auth0 Certificate

Security Settings #

SAML Points with Checkboxes
For increased security we recommend enabling the following settings if supported by your environment.
Indicates that the nameID of the <samlp:logoutRequest> sent by this SP will be encrypted.
Indicates whether the <samlp:AuthnRequest> messages sent by this SP will be signed. [Metadata of the SP will offer this info]
Indicates whether the <samlp:logoutRequest> messages sent by this SP will be signed.
Indicates whether the <samlp:logoutResponse> messages sent by this SP will be signed.
Whether the metadata should be signed.
Indicates a requirement for the <samlp:Response>, <samlp:LogoutRequest>, and <samlp:LogoutResponse> elements received by this SP to be signed.
Indicates a requirement for the <saml:Assertion> elements received by this SP to be signed. [Metadata of the SP will offer this info]
Indicates a requirement for the <saml:Assertion> elements received by this SP to be encrypted.
Indicates a requirement for the NameID element on the SAMLResponse received by this SP to be present.
Indicates a requirement for the NameID received by this SP to be encrypted.
Indicates if the SP will validate all received XML.
ADFS URL-Encodes SAML data as lowercase, and the toolkit by default uses uppercase. Enable for ADFS compatibility on signature verification. Algorithm that the toolkit will use on signing process.
Retrieve query parameters from $_SERVER. Some SAML servers require this on SLO requests.
Nextcloud SAML Security Settings

You cannot copy content of this page