Skip to main content

SAML source

The SAML source lets users log in to authentik with an external SAML identity provider (IdP). In this setup, authentik is the SAML service provider (SP). Like the SAML provider, it supports signed requests. Guides for specific identity providers are under External identity providers.

SAML source or SAML provider?

This page covers the SAML source, where an external IdP logs users in to authentik. To let an application log users in with authentik as the SAML IdP, use the SAML provider instead.

Terminology​

AbbreviationNameDescription
IdPIdentity providerThe authoritative SAML authentication source that holds the user database.
SPService providerThe client that is connected to an IdP, usually providing a service, such as a web application. In the current context, authentik is the SP.
-AssertionA message sent by the IdP asserting that the user has been identified.
ACSAssertion Consumer ServiceThe service on the SP side that consumes the assertion sent from the IdP.
SSO URLSingle sign-on URLThe URL on the IdP side that the SP calls to initiate an authentication process.
SLO URLSingle logout URLThe URL on the IdP side that the SP calls to invalidate a session and log the user out of the IdP and the SP.

Example configuration​

If you have the IdP metadata, you can extract the values that you need from it. The following table provides example values for a basic IdP metadata file.

NameExampleDescription
NameCompany SAMLThe name of the authentication source
Slugcompany-samlThe slug used in URLs for the source
Iconbranding/company-icon.svgOptional icon or image shown for the source. See File picker values.
SSO URLhttps://saml.company/login/samlThe SingleSignOnService URL for the IdP. This value can be found in the metadata or IdP documentation. There can be different URLs for different binding types, such as HTTP-Redirect and HTTP-POST. Use the URL for the binding type that you choose below.
SLO URLhttps://saml.company/logout/samlThe URL that is called when a user logs out of authentik. This can be used to automatically log the user out of the SAML IdP after logging out of authentik. Not all IdPs support or require this behavior.
Binding TypeHTTP-POSTHow authentik communicates with the SSO URL (302 redirect or POST request). This will depend on what the IdP supports.
Allow IDP-initiated loginsFalseWhether to allow the IdP to log users into authentik without any interaction. Activating this can be a security risk because this request is not verified, and could be used by an attacker to authenticate a user without interaction.
Force authenticationFalseWhen enabled, authentik requests the IdP to force re-authentication of the user, even if they already have an active session with the IdP.
Issuer overridehttps://authentik.company/source/saml/<source-slug>/metadata/The identifier (Entity ID) for the authentik instance in the SAML federation. This is optional and defaults to the metadata URL of the source, as shown in the example. To override it, set any value that the IdP recognizes. This must match what you register on the IdP side.
NameID PolicyPersistentDepending on what the IdP sends as persistent ID, some IdPs use the username or email address while others use a random string or hashed value. If the user in authentik receives a random string as a username, try using Email address or Windows.
Flow settingsDefaultIf there are custom flows in your instance for external authentication, select them here.

SP-initiated and IdP-initiated login​

A SAML login can start at either the SP or the IdP. With a SAML source, authentik is the SP.

In an SP-initiated login, the user starts at authentik, for example by selecting the source on the authentik login page. authentik sends an authentication request to the IdP, and the IdP answers it with a SAML response. authentik only accepts a response that answers the request it sent. This is the default.

In an IdP-initiated login, the user starts at the IdP, for example by selecting an authentik tile in the IdP's app portal. The IdP sends a SAML response that authentik never asked for.

authentik rejects IdP-initiated logins unless Allow IDP-initiated logins is enabled on the source.

warning

With Allow IDP-initiated logins enabled, authentik stops checking that a response answers a request it sent, for every login through this source, SP-initiated logins included. A response that the user didn't ask for can then log them in without their interaction. Enable this setting only if your IdP requires IdP-initiated login.

When authentik is the IdP for an application through a SAML provider, the roles are reversed: an IdP-initiated login starts in authentik. For its URL, see SAML bindings and endpoints.

Transient users and account lifetime​

When the IdP sends a transient NameID, authentik creates a temporary user linked to the SAML source. This is determined by the NameID format in the assertion, even if the source's NameID Policy requests another format.

Temporary users are deleted:

  • when they log out of authentik, or
  • by a cleanup task after they expire.

The Delete temporary users after setting determines the expiration time from account creation. The default is days=1; you can set values such as hours=8 or hours=1;minutes=30. This setting does not delay deletion on logout. Cleanup tasks run periodically, rather than at the exact expiration time, and do not check for active sessions, so an expired temporary user can be deleted while still logged in.

Mapping a transient user's username or email to a stable value does not make the account persistent or prevent deletion.

Use Persistent NameIDs when users need to keep the same authentik account across logins. Configure the IdP to send a stable persistent NameID and set the source's NameID Policy to Persistent. authentik uses the NameID to find the existing source connection on subsequent logins.

Add authentik as a service provider with your IdP​

This depends on the software that you use for your IdP. On the Metadata tab in the SAML federation source, you can download the metadata for the service provider. This should let you import the service provider into most IdPs. If this does not work, the important parts are:

  • Entity ID: Taken from the Issuer override field above

  • Return URL/ACS URL: https://authentik.company/source/saml/<source-slug>/acs/

  • Certificate: If you have chosen to sign your outgoing requests, use the public side of the certificate that you specified in the settings.

  • Encryption certificate: If an encryption keypair is configured, use its public certificate. In authentik 2026.11 and later, when an encryption keypair is configured, the metadata advertises the following assertion-encryption algorithms in <EncryptionMethod> elements, in order of preference:

    1. AES256-GCM
    2. AES128-GCM
    3. AES256-CBC
    4. AES128-CBC

    The metadata also advertises RSA-OAEP for key transport.

Example IdP metadata​

<md:EntityDescriptor entityID="https://saml.company/idp">
<md:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol" WantAuthnRequestsSigned="false">
<md:NameIDFormat>
urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
</md:NameIDFormat>
<md:NameIDFormat>
urn:oasis:names:tc:SAML:2.0:nameid-format:transient
</md:NameIDFormat>
<md:NameIDFormat>
urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
</md:NameIDFormat>
<md:NameIDFormat>
urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
</md:NameIDFormat>
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://saml.company/login/saml/"/>
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://saml.company/login/saml/"/>
</md:IDPSSODescriptor>
<md:Organization>
<md:OrganizationName xml:lang="en">Example Organization</md:OrganizationName>
<md:OrganizationDisplayName xml:lang="en">Example Organization</md:OrganizationDisplayName>
<md:OrganizationURL xml:lang="en">http://www.company</md:OrganizationURL>
</md:Organization>
<md:ContactPerson contactType="technical">
<md:Company>Example Organization</md:Company>
<md:GivenName>John</md:GivenName>
<md:SurName>Doe</md:SurName>
<md:EmailAddress>john.doe@company</md:EmailAddress>
<md:TelephoneNumber>012 345 67890</md:TelephoneNumber>
</md:ContactPerson>
<md:ContactPerson contactType="support">
<md:Company>Example Organization</md:Company>
<md:GivenName>Helpdesk</md:GivenName>
<md:SurName>Support</md:SurName>
<md:EmailAddress>helpdesk@company</md:EmailAddress>
<md:TelephoneNumber>012 345 67890</md:TelephoneNumber>
</md:ContactPerson>
</md:EntityDescriptor>

SAML source property mappings​

See the overview for information on how property mappings work.

SAML source property mappings customize the user and group properties created from a SAML assertion. authentik parses the assertion's AttributeStatement into the properties dictionary before custom mappings run, using each SAML attribute's Name as the dictionary key. Custom mappings can then translate those SAML attribute names to authentik user fields such as username, email, name, and attributes.

Property mappings do not change the internal SAML source connection identifier, which is based on the assertion's NameID. To persist mapped user fields, ensure the source flow that runs for the user includes a User Write stage before the user login stage. For existing users, this is the source's authentication flow; for new users, this is the source's enrollment flow.

Expression data​

The following variables are available to SAML source property mappings:

The parsed XML objects use Python's standard xml.etree.ElementTree API.

  • root: The parsed XML root containing data from the source.
  • assertion: The parsed XML element containing the SAML assertion.
  • name_id: The parsed XML element identifying the user.
  • properties: A Python dictionary containing the source's parsed SAML attributes and the results of any previously run mappings.

Example​

This example maps common SAML attributes to authentik user fields. Replace the attribute names with the SAML attribute Name values sent by the external identity provider connected to this SAML source.

email = properties.get("email") or properties.get("urn:oid:0.9.2342.19200300.100.1.3")
first_name = properties.get("firstname") or properties.get("urn:oid:2.5.4.42")
last_name = properties.get("lastname") or properties.get("urn:oid:2.5.4.4")

return {
"username": email,
"email": email,
"name": f"{first_name or ''} {last_name or ''}".strip(),
"attributes": {
"first_name": first_name,
"last_name": last_name,
},
}

If you need to read the XML assertion directly, use the SAML assertion namespace when searching for elements:

NS_SAML_ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"

attributes = {}
for attribute in assertion.findall(f".//{{{NS_SAML_ASSERTION}}}Attribute"):
values = [
value.text
for value in attribute.findall(f"{{{NS_SAML_ASSERTION}}}AttributeValue")
]
attributes[attribute.attrib["Name"]] = values[0] if len(values) == 1 else values

return {
"email": attributes.get("email"),
}