Skip to content

Configure SAML2 SSO Login as an Administrator (Keycloak and Authentik Examples)

This document describes how to configure a SAML2 SSO Provider in SwanLab, as well as the SP Metadata, ACS, EntityID, and attribute mapping required on the IdP side.

1. Feature Introduction

SAML2 SSO applies to scenarios where an enterprise already has a SAML IdP. SwanLab currently initiates login as an SP (Service Provider), and the request is signed. After the IdP returns a SAMLResponse, SwanLab validates the response in ACS, parses the Assertion, and maps the third-party user through Attributes.

Account policy:

  • First-time SAML2 login automatically creates and binds a SwanLab account.
  • Bound users log in directly after authentication succeeds.

Currently, only SP-initiated login is supported. Users cannot initiate login directly from the IdP portal.

2. Procedure

  1. In the SwanLab administrator control panel, click to create SAML2.

  1. Fill in the basic configuration.
FieldRequiredDescription
NameYesUnique Provider identifier. Up to 25 characters. Only letters, digits, underscores, and hyphens are allowed
Display nameYesName shown on the login button. Up to 100 characters

  1. Fill in the SAML2 configuration.
FieldRequiredDescription
SAML Metadata URLYesURL of the IdP Metadata XML
SAML private key contentYesPrivate key PEM content used by SwanLab as the SP
SAML certificate contentYesCertificate PEM content used by SwanLab as the SP

SwanLab signs AuthnRequests, so the certificate is required. When configuring the IdP, you also need to enter the certificate used here on the IdP side.

  1. Fill in user mapping.
FieldRequiredDescription
User ID fieldYesField name corresponding to the third-party unique user ID
Username fieldYesField name corresponding to the third-party username. It is used as the default username during automatic account creation
Recommended unique user ID fieldRecommended username field
Stable Attributes such as uid, employeeNumber, and emailusername, uid

  1. Fill in the display configuration.

We recommend using an online link for the Icon URL.

  1. Enable the IdP.

After creation, you can view existing IdPs in the list. After enabling one, you can test and use it:

  1. View it in the login list.

3. SwanLab SP Addresses

SwanLab generates independent SP addresses for each SAML2 Provider.

SP Metadata address:

text
https://<SwanLab external access address>/api/auth/sso/saml2/metadata/<Provider name>

ACS address:

text
https://<SwanLab external access address>/api/auth/sso/saml2/acs/<Provider name>

EntityID:

text
https://<SwanLab external access address>/api/auth/sso/saml2/metadata/<Provider name>

Example:

text
SP Metadata: https://swanlab.example.com/api/auth/sso/saml2/metadata/corp-saml2
ACS:         https://swanlab.example.com/api/auth/sso/saml2/acs/corp-saml2
EntityID:    https://swanlab.example.com/api/auth/sso/saml2/metadata/corp-saml2

4. IdP-side Configuration

When creating a SAML application in the IdP, you may need to configure:

IdP fieldSwanLab value
Single sign-on URL / ACS URLSwanLab ACS address
Recipient URLSwanLab ACS address
Destination URLSwanLab ACS address
Audience URI / SP Entity IDSwanLab EntityID
Name ID formatDefault or unspecified
Response signatureRecommended to enable
Assertion signatureRecommended to enable
SP-initiated loginMust be allowed

SwanLab signs AuthnRequests, so the IdP must accept signed requests. The current SAML Redirect Binding signature algorithm is selected as RSA-SHA256 or ECDSA-SHA256 according to the private key type.

  1. Keycloak configuration example:

The Client ID is the Issuer. It usually needs to be configured as the SP Issuer address, which corresponds to the SwanLab EntityID address:

text
https://<SwanLab external access address>/api/auth/sso/saml2/metadata/<Provider name>

You also need to upload the SwanLab certificate configured earlier to Keycloak; otherwise, Keycloak cannot parse the request:

  1. Authentik configuration example:

The following fields are explicitly required:

  • ACS URL: the corresponding SwanLab ACS address, https://swanlab.example.com/api/auth/sso/saml2/acs/corp-saml2
  • Issuer: the corresponding SwanLab EntityID, https://swanlab.example.com/api/auth/sso/saml2/metadata/corp-saml2
  • Audience: the corresponding SwanLab EntityID address, https://swanlab.example.com/api/auth/sso/saml2/metadata/corp-saml2

You also need to configure certificates:

  • Signing certificate: Authentik self-signed certificate
  • Verification certificate: the certificate configured in SwanLab