> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/en/org/sso/sso-saml.md).

# SAML Integration

Integrate with identity providers such as Azure AD, Okta, and Google Workspace via the SAML 2.0 protocol

SAML (Security Assertion Markup Language) is a standard authentication protocol widely adopted by enterprise-grade applications.

**Target audience**: Enterprises that have deployed a SAML identity provider (such as Microsoft Entra ID / Azure AD, Okta, Google Workspace)

**Key advantages**:

* Industry-standard protocol with high compatibility
* Identifies users by Email and automatically creates an account on first sign-in (only the Email and display name are read; groups, departments, and other attributes are not)
* Integrates with multi-factor authentication (MFA)
* Supports Single Logout (SLO)

## Setup Steps <a href="#setup-steps" id="setup-steps"></a>

### 1. Fill in IdP Information in the MaiAgent Backend <a href="#step-1-fill-idp-info" id="step-1-fill-idp-info"></a>

After selecting the <mark style="color:blue;">SAML</mark> authentication type, first fill in the <mark style="color:blue;">Authentication Source Name</mark> (used to generate SP endpoint URLs, for example `my-company`), then provide the IdP settings using **one** of the following two modes. The two modes cannot be filled in at the same time; the form cannot be saved if both are provided.

| Mode            | Fields to fill in                                                                                                                                                                    | When to use                                                                                                                                                                                                                                                          |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A: Metadata URL | <mark style="color:blue;">IdP Metadata URL</mark>                                                                                                                                    | The IdP provides a publicly readable metadata URL (for example, Microsoft Entra ID). When you save, the system downloads and parses it, automatically obtaining the Entity ID, SSO URL, and certificate; if MaiAgent cannot reach this URL, the form cannot be saved |
| B: Manual setup | <mark style="color:blue;">IdP Entity ID</mark>, <mark style="color:blue;">IdP SSO URL</mark>, <mark style="color:blue;">IdP X.509 Certificate</mark> (all three fields are required) | The IdP only lets you download a metadata file and has no metadata URL (for example, Google Workspace). For the certificate, paste the base64 content between `BEGIN CERTIFICATE` and `END CERTIFICATE` in the PEM                                                   |

<mark style="color:blue;">Email Domain</mark> is optional: once set, members whose Email uses this domain are automatically redirected to this SAML sign-in when they enter their Email on the sign-in page.

### 2. Obtain SP (MaiAgent Side) Information <a href="#step-2-get-sp-info" id="step-2-get-sp-info"></a>

After you fill in the authentication source name, the system automatically generates the following SP information, displayed on the settings page:

| SP Field                                 | Format                                            | Description                           |
| ---------------------------------------- | ------------------------------------------------- | ------------------------------------- |
| Entity ID                                | `https://{domain}/accounts/saml/{name}/metadata/` | Provided to the IdP for configuration |
| ACS URL (Assertion Consumer Service URL) | `https://{domain}/accounts/saml/{name}/acs/`      | Provided to the IdP for configuration |
| Login URL                                | `https://{API domain}/auth/saml/{name}/login/`    | SAML sign-in entry point              |

Each of the three values has its own purpose: the Entity ID is the name by which the IdP identifies MaiAgent; the ACS URL (Assertion Consumer Service) is the address to which the IdP sends the signed SAML response after the user signs in successfully at the IdP, and where MaiAgent verifies it and completes the sign-in. The IdP only sends to pre-registered addresses, so paste it exactly as is (including the trailing `/`); the Login URL is the entry point where users start SSO sign-in and does not need to be entered into the IdP. For technical details, see the Technical Manual [SAML SSO Integration](https://docs.maiagent.ai/tech/identity-and-access/sso-overview/saml-sso).

{% hint style="info" %}
The SP information area provides a <mark style="color:blue;">Copy</mark> button so you can copy the URLs directly into the IdP's configuration interface.
{% endhint %}

### 3. Configure the MaiAgent Application in the Identity Provider (IdP) <a href="#step-3-configure-idp" id="step-3-configure-idp"></a>

Using **Microsoft Entra ID (Azure AD)** as an example:

1. Sign in to the [Azure Portal](https://portal.azure.com/) > <mark style="color:blue;">Microsoft Entra ID</mark> > <mark style="color:blue;">Enterprise applications</mark>
2. Click <mark style="color:blue;">New application</mark> > <mark style="color:blue;">Create your own application</mark>
3. Select "**Integrate any other application you don't find in the gallery (Non-gallery)**"

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-0635609d8cfbc379308c3c09cf2d36b4bf5feccd%2Fsso-azure-01-create-enterprise-app.png?alt=media" alt="Create enterprise application"><figcaption><p>Create a custom enterprise application in Azure AD</p></figcaption></figure>

4. Select the enterprise application you just created

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-7a355995c181ba03d74f063a04cf14f33a36c292%2Fsso-azure-02-select-enterprise-app.png?alt=media" alt="Select enterprise application"><figcaption><p>Select the specified enterprise application</p></figcaption></figure>

5. Open the enterprise application and click <mark style="color:blue;">Single sign-on</mark> > <mark style="color:blue;">SAML</mark> on the left

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-833772e0e67721e2176efc5172b2b60aea3a66ff%2Fsso-azure-03-sso-saml.png?alt=media" alt="Select SAML"><figcaption><p>Select SAML as the single sign-on method</p></figcaption></figure>

6. In the <mark style="color:blue;">Basic SAML Configuration</mark> section, enter the MaiAgent SP information:
   * **Identifier (Entity ID)**: Enter the Entity ID generated by MaiAgent
   * **Reply URL (Assertion Consumer Service URL)**: Enter the ACS URL generated by MaiAgent
7. Save the settings

### 4. Get the Values from the IdP and Fill Them Back into MaiAgent <a href="#step-4-fill-idp-values-back" id="step-4-fill-idp-values-back"></a>

At the bottom of the Azure AD <mark style="color:blue;">Set up Single Sign-On with SAML</mark> page, find the following information and, according to the mode in [Step 1](#step-1-fill-idp-info), fill in one of the sets into the SAML settings form in the MaiAgent backend:

| Mode            | Azure AD Field                                                       | Corresponding MaiAgent Field |
| --------------- | -------------------------------------------------------------------- | ---------------------------- |
| A (recommended) | App Federation Metadata Url                                          | IdP Metadata URL             |
| B               | Microsoft Entra Identifier                                           | IdP Entity ID                |
| B               | Login URL                                                            | IdP SSO URL                  |
| B               | "Certificate (Base64)" downloaded from the SAML Certificates section | IdP X.509 Certificate        |

When using Mode A, fill in only the IdP Metadata URL and leave the other three fields empty.

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-73eb33f62fc8b287844c32ca6fca687e5b511450%2Fsso-azure-05-idp-info.png?alt=media" alt="IdP information"><figcaption><p>Obtain the Microsoft Entra Identifier, Login URL, and metadata URL from Azure AD</p></figcaption></figure>

### 5. Assign Users and Groups <a href="#step-5-assign-users-groups" id="step-5-assign-users-groups"></a>

In the Azure AD enterprise application, click <mark style="color:blue;">Users and groups</mark> > <mark style="color:blue;">Add user/group</mark>, and add the employees or groups that need access to MaiAgent.

<figure><img src="https://1360999650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6v6TNkkOQVfRYfcNirHL%2Fuploads%2Fgit-blob-1712c334ffa9fc2b078865f6808ab6ae12aec56f%2Fsso-azure-06-add-users-groups.png?alt=media" alt="Add users and groups"><figcaption><p>Add the employees or groups that need access to MaiAgent to the enterprise application</p></figcaption></figure>

### 6. Save and Confirm <a href="#step-6-save-and-confirm" id="step-6-save-and-confirm"></a>

Click the <mark style="color:blue;">Save</mark> button in the MaiAgent backend, and the <mark style="color:blue;">Confirm Authentication Method Change</mark> window appears. Make sure the IdP-side configuration is complete, then click <mark style="color:blue;">Confirm Change</mark> to finish the setup.

{% hint style="warning" %}
After SAML is enabled, members who have set a password can still sign in with Email + password; the system does not automatically disable password sign-in. To prevent a member from accessing the organization with a password, or to automate deactivation when someone leaves, see [Offboarding and Deactivating Members](https://docs.maiagent.ai/maiagent-user-guide/en/org/sso.md#offboarding).
{% endhint %}

## SAML Attribute Mapping <a href="#saml-attribute-mapping" id="saml-attribute-mapping"></a>

MaiAgent reads only two attributes from the SAML response: **Email** (required, used as the account identifier) and **display name**. The mapping rules are fixed and cannot be customized in the backend; other attributes such as groups, departments, and job titles are not read, and roles are not synchronized.

* **Email**: The default output of Microsoft Entra ID and ADFS works as is; for other IdPs, make sure an Email attribute is sent, or set the NameID format to emailAddress. For the three acceptable Email sources and the order in which they are read, see Section 2.2 "User Attribute Mapping" of the Technical Manual [SAML SSO Integration](https://docs.maiagent.ai/tech/identity-and-access/sso-overview/saml-sso).
* **Display name**: Written only on first sign-in, when the account is created; if no display name is sent, the text before the @ in the Email is used instead. Later name changes on the IdP side are not synchronized to MaiAgent.

## Other SAML IdP Settings <a href="#other-saml-idp-settings" id="other-saml-idp-settings"></a>

MaiAgent's SAML integration is not limited to Microsoft Entra ID. Any identity provider that supports the SAML 2.0 standard can be integrated. Common IdPs include:

* **Okta**: Add a SAML 2.0 App under Applications
* **Google Workspace**: Configure under Admin Console > Security > SSO
* **ADFS**: Add under Relying Party Trusts; for full steps, see [ADFS Integration](https://docs.maiagent.ai/maiagent-user-guide/en/org/sso/sso-saml/sso-saml-adfs.md)

The logic is the same: enter MaiAgent's SP information (Entity ID, ACS URL) into the IdP, then fill the IdP's information back into MaiAgent. If a Metadata URL is available, fill in only the Metadata URL (Mode A); otherwise, fill in the Entity ID, SSO URL, and X.509 certificate (Mode B).

## SAML Security Features <a href="#saml-security-features" id="saml-security-features"></a>

* Supports SAML 2.0 HTTP Redirect Binding
* Session Index tracking to ensure sign-out operations are correct
* NameID format uses emailAddress to ensure consistent user identification
* Sign-in cookie settings: `Secure=True`, `SameSite=None`, `HttpOnly=True`, with a validity of 5 minutes

## Settings Quick Reference <a href="#settings-quick-reference" id="settings-quick-reference"></a>

| Field                      | Required            | Format                                                    | Example                                                                                   |
| -------------------------- | ------------------- | --------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| Authentication Source Name | Yes                 | Lowercase letters, digits, and hyphens; max 31 characters | `my-company`                                                                              |
| IdP Metadata URL           | Required for Mode A | HTTPS URL                                                 | `https://login.microsoftonline.com/.../federationmetadata/2007-06/federationmetadata.xml` |
| IdP Entity ID              | Required for Mode B | URI                                                       | `https://sts.windows.net/{tenant-id}/`                                                    |
| IdP SSO URL                | Required for Mode B | HTTPS URL                                                 | `https://login.microsoftonline.com/{tenant-id}/saml2`                                     |
| IdP X.509 Certificate      | Required for Mode B | Base64 content between BEGIN / END CERTIFICATE in the PEM | `MIID...`                                                                                 |
| Email Domain               | No                  | Domain format                                             | `company.com`                                                                             |

{% hint style="info" %}
Fill in either Mode A or Mode B; they cannot be provided at the same time.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/maiagent-user-guide/en/org/sso/sso-saml.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
