> 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-cloudflare-access.md). Agents can also search and read this documentation through its [MCP server](https://docs.maiagent.ai/~gitbook/mcp).

# Cloudflare Access Integration

Organizations using Cloudflare Zero Trust can let members sign in to MaiAgent through Cloudflare Access. This guide covers configuration fields (Team Name, AUD Tag, email domain, and automatic member

If your company already uses Cloudflare Zero Trust Access to manage access to internal systems, you can configure Cloudflare Access as a third-party sign-in method for MaiAgent. After members open the sign-in link, they authenticate through Cloudflare Access (and any identity provider your company has connected to Access), then automatically sign in to MaiAgent.

**Who this is for**: Enterprises that already use Cloudflare Zero Trust Access and want to keep using the same sign-in and access policies.

## Requirements <a href="#requirements" id="requirements"></a>

* Your organization must be on an Enterprise plan. Organizations on other plans do not see <mark style="color:blue;">Third-party Sign-in Settings</mark> under <mark style="color:blue;">Management Actions</mark>.
* Only the organization owner can save authentication settings.
* Each organization can use only one authentication type at a time. For the effects of switching, see [Switching Authentication Types](https://docs.maiagent.ai/maiagent-user-guide/en/org/sso.md#switch-auth-type).

## How It Works <a href="#how-it-works" id="how-it-works"></a>

1. A member opens the sign-in link generated by MaiAgent.
2. MaiAgent redirects the member to the <mark style="color:blue;">Server URL</mark> you configured: the entry URL protected by Cloudflare Access.
3. Cloudflare Access intercepts the request and requires the member to sign in according to your company's Access policies.
4. After successful authentication, Cloudflare forwards the request with an identity token to MaiAgent. MaiAgent uses the <mark style="color:blue;">Team Name</mark> to retrieve Cloudflare's public keys, verify the signature, and check the <mark style="color:blue;">Application Audience (AUD) Tag</mark>.
5. MaiAgent finds the account matching the email address in the token (or creates one automatically, depending on your settings), and the member is signed in to MaiAgent.

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

Prepare the following information in Cloudflare Zero Trust:

| Item               | Description                                                                                                                                                                                                            |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Team Name          | Your Zero Trust team name. If your team domain is `acme.cloudflareaccess.com`, the team name is `acme`                                                                                                                 |
| Access Application | The Access application that protects the entry URL. The sign-in callback path is `/api/auth/cloudflare/<認證來源名稱>/callback/`. This path must be protected by the application, and requests must be forwarded to MaiAgent |
| AUD Tag            | The Application Audience (AUD) Tag of the Access Application above                                                                                                                                                     |

{% hint style="warning" %}
How the entry URL forwards requests to MaiAgent depends on your organization's deployment. Before configuring it, confirm the entry URL and forwarding method with your MaiAgent contact.
{% endhint %}

## Configure in MaiAgent <a href="#configure-in-maiagent" id="configure-in-maiagent"></a>

1. In the left menu, click <mark style="color:blue;">Organization Settings</mark> → <mark style="color:blue;">Organization Overview</mark>, then click <mark style="color:blue;">Third-party Sign-in Settings</mark> in the <mark style="color:blue;">Management Actions</mark> section.
2. Select <mark style="color:blue;">Cloudflare Access</mark> from the authentication type cards. The <mark style="color:blue;">Cloudflare Access Settings</mark> section appears below.
3. Fill in the fields in the table below and click <mark style="color:blue;">Save</mark>. The <mark style="color:blue;">Confirm Authentication Method Change</mark> dialog appears. Read the notes, then click <mark style="color:blue;">Confirm Change</mark>.

| Field                                                           | Required | Description                                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:blue;">Authentication Source Name</mark>     | Yes      | A unique name that identifies this authentication source and becomes part of the sign-in link. Use only lowercase English letters, numbers, and hyphens (-), up to 31 characters. `maiagent` is not allowed. The rules are the same as for other authentication types; see [Authentication Source Naming Rules](https://docs.maiagent.ai/maiagent-user-guide/en/org/sso.md#auth-source-naming-rules) |
| <mark style="color:blue;">Server URL</mark>                     | Yes      | The entry URL protected by Cloudflare Access, such as `https://portal.acme.com`                                                                                                                                                                                                                                                                                                                      |
| <mark style="color:blue;">Team Name</mark>                      | Yes      | Your Cloudflare Zero Trust team name, such as `acme`                                                                                                                                                                                                                                                                                                                                                 |
| <mark style="color:blue;">Application Audience (AUD) Tag</mark> | Yes      | The AUD Tag of the Access Application                                                                                                                                                                                                                                                                                                                                                                |
| <mark style="color:blue;">Email Domain</mark>                   | No       | When set, only email addresses in this domain, such as `acme.com`, can sign in through this authentication source. The same domain cannot also be used by another organization's authentication source                                                                                                                                                                                               |
| <mark style="color:blue;">Automatically Create Members</mark>   | No       | Off by default. See [Account Matching](#account-matching) for details                                                                                                                                                                                                                                                                                                                                |

## Sign-in Link <a href="#login-url" id="login-url"></a>

After you save, a <mark style="color:blue;">Sign-in URL</mark> is generated in the <mark style="color:blue;">Sign-in Link</mark> section. Copy it and share it with members so they can open the link to sign in through Cloudflare Access. Before you save, the page displays “Save your settings first. The system will then generate a sign-in link automatically.”

{% hint style="info" %}
The sign-in page's automatic redirect to single sign-on after entering an email address applies only to SAML. Members using Cloudflare Access must use the sign-in link directly. For example, add it to your company portal or bookmarks.
{% endhint %}

## Account Matching <a href="#account-matching" id="account-matching"></a>

MaiAgent matches accounts using the email address verified by Cloudflare and determines whether to allow sign-in based on <mark style="color:blue;">Automatically Create Members</mark>:

| Scenario                                                        | Automatically Create Members: Off | Automatically Create Members: On                                                                                              |
| --------------------------------------------------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| Already a member of this organization                           | Sign in                           | Sign in                                                                                                                       |
| Has a MaiAgent account but is not a member of this organization | Deny sign-in                      | Add to this organization and sign in                                                                                          |
| Does not yet have a MaiAgent account                            | Deny sign-in                      | Create an account, add to this organization, and sign in; the display name defaults to the part of the email address before @ |
| Email address is outside the configured email domain            | Deny sign-in                      | Deny sign-in                                                                                                                  |

Members who already have a MaiAgent account can continue using their existing sign-in methods, such as a username and password. Cloudflare Access provides an additional way to sign in.

## Sign-in Error Messages <a href="#error-messages" id="error-messages"></a>

| Message                                                    | Common Cause                                                                                                                                 | Resolution                                                                                                                |
| ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| Authentication failed. Please sign in again                | The request is missing Cloudflare's identity token, or token verification failed (Team Name or AUD Tag mismatch)                             | Confirm that the callback path is protected by the Access Application and that both fields match the values in Cloudflare |
| This account is not authorized to access this organization | The account is not a member of this organization and automatic member creation is off, or the email address is outside the configured domain | Add the member to the organization first, or enable <mark style="color:blue;">Automatically Create Members</mark>         |
| This sign-in method is currently disabled                  | Sign-in through this authentication source has been disabled                                                                                 | Contact your MaiAgent representative                                                                                      |
| Sign-in timed out. Please sign in again                    | The one-time sign-in code has already been used or has expired, for example after refreshing the page during sign-in                         | Click <mark style="color:blue;">Sign In Again</mark> and try again                                                        |
| Sign-in was not completed. Please sign in again            | The callback page was opened directly (without Cloudflare authentication), or the flow was interrupted                                       | Start again from the URL in the sign-in link card                                                                         |

## Frequently Asked Questions <a href="#faq" id="faq"></a>

#### Q: Does signing out of MaiAgent also sign me out of Cloudflare Access? <a href="#faq-logout" id="faq-logout"></a>

No. Signing out only ends your MaiAgent session. Your Cloudflare Access session depends on your company's session settings in Cloudflare.

#### Q: Can I restrict sign-in to colleagues from a specific domain? <a href="#faq-restrict-domain" id="faq-restrict-domain"></a>

Yes. Once you set <mark style="color:blue;">Email Domain</mark>, email addresses from other domains are rejected even if Cloudflare authenticates them. Configure more detailed access rules, such as allowing only certain departments, in Cloudflare Access policies.

#### Q: Why does saving show “This email domain is already in use”? <a href="#faq-domain-in-use" id="faq-domain-in-use"></a>

Another authentication source already uses this domain. Each domain can be associated with only one authentication source. Use a different domain, or leave the field blank to apply no domain restriction.

## Further Reading <a href="#further-reading" id="further-reading"></a>

* [Third-party Sign-in (SSO)](https://docs.maiagent.ai/maiagent-user-guide/en/org/sso.md): Overview of authentication types and the effects of switching between them
* [Member Management](https://docs.maiagent.ai/maiagent-user-guide/en/org/overview/member.md): Add members to your organization in advance
* [Role and Permission Management](https://docs.maiagent.ai/maiagent-user-guide/en/org/roles/role-permission.md): Set roles and permissions for members who sign in


---

# 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-cloudflare-access.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.
