Microsoft Entra ID 凭据(Microsoft Entra ID credentials)#
你可以使用以下凭据验证以下节点:
🌐 You can use these credentials to authenticate the following nodes:
先决条件(Prerequisites)#
- 创建 Microsoft Entra ID 账户或订阅。
- 如果用户账户由企业 Microsoft Entra 账户管理,管理员账户已为该用户启用“用户可以同意应用代表其访问公司数据”选项(参见 Microsoft Entra 文档)。
当你创建 Microsoft Azure 账户时,微软会包含一个免费的 Entra ID 计划。
🌐 Microsoft includes an Entra ID free plan when you create a Microsoft Azure account.
支持的身份验证方法(Supported authentication methods)#
- OAuth2
相关资源(Related resources)#
有关该服务的更多信息,请参阅 Microsoft Entra ID 的文档。
🌐 Refer to Microsoft Entra ID's documentation for more information about the service.
使用 OAuth2(Using OAuth2)#
Note for n8n Cloud users
Cloud users don't need to provide connection details. Select Connect my account to connect through your browser.
对于自托管用户,从头开始配置 OAuth2 主要分为两个步骤:
🌐 For self-hosted users, there are two main steps to configure OAuth2 from scratch:
按照下面的每个步骤的详细说明操作。有关 Microsoft OAuth2 网页流程的更多详细信息,请参阅 Microsoft 身份验证和授权基础。
🌐 Follow the detailed instructions for each step below. For more detail on the Microsoft OAuth2 web flow, refer to Microsoft authentication and authorization basics.
注册应用(Register an application)#
使用 Microsoft Identity Platform 注册应用:
🌐 Register an application with the Microsoft Identity Platform:
- 打开 Microsoft 应用注册门户。
- 选择 注册一个应用。
- 为你的应用输入一个名称。
- 在 支持的账户类型 中,选择 任何组织目录中的账户(Any Azure AD directory - 多租户)和个人 Microsoft 账户(例如 Skype、Xbox)。
- 在 注册应用 中:
- 从你的 n8n 凭证中复制 OAuth 回调 URL。
- 将其粘贴到 重定向 URI(可选) 字段中。
- 选择 选择一个平台 > 网页。
- 选择 注册 以完成创建你的应用。
- 复制 应用(客户端)ID 并将其粘贴到 n8n 中作为 客户端 ID。
有关更多信息,请参阅 在 Microsoft 身份平台注册应用 。
🌐 Refer to Register an application with the Microsoft Identity Platform for more information.
生成客户端密钥(Generate a client secret)#
创建应用后,为其生成客户端密钥:
🌐 With your application created, generate a client secret for it:
- 在你的 Microsoft 应用页面上,选择左侧导航中的 证书与密钥。
- 在 客户端密钥 中,选择 + 新建客户端密钥。
- 为你的客户端密钥输入一个描述,例如
n8n credential。 - 选择 添加。
- 复制 值 列中的 秘密。
- 将其粘贴到 n8n 作为 客户端密钥。
- 在 n8n 中选择 连接我的账户 以完成连接设置。
- 登录你的 Microsoft 账户并允许应用访问你的信息。
有关添加客户端密钥的更多信息,请参阅微软的添加凭据。
🌐 Refer to Microsoft's Add credentials for more information on adding a client secret.
Microsoft Graph API 基础 URL(Microsoft Graph API Base URL)#
Microsoft Entra ID 凭据扩展了 Microsoft OAuth2 API 凭据,并支持不同的 Microsoft 云环境。请根据你的租户云环境选择合适的端点:
🌐 Microsoft Entra ID credentials extend the Microsoft OAuth2 API credentials and support different Microsoft cloud environments. Select the appropriate endpoint based on your tenant's cloud environment:
- 全局:用于标准 Microsoft 365 租户(默认)
- 美国政府:用于 Azure 美国政府(GCC)租户
- 美国政府国防部 (DOD):用于 Azure 美国政府国防部租户
- 中国:适用于由 21Vianet 在中国运营的 Microsoft 365
政府云授权网址
如果你正在使用政府云租户,你可能还需要在凭据中更新 Authorization URL 和 Access Token URL 字段,以使用政府云端点。例如:
- 美国政府:使用 https://login.microsoftonline.us/{tenant}/oauth2/v2.0/authorize 和 https://login.microsoftonline.us/{tenant}/oauth2/v2.0/token
- 将 {tenant} 替换为你的租户 ID,或者对于多租户应用使用 common
设置自定义范围(Setting custom scopes)#
Microsoft Entra ID 凭据默认使用以下范围:
🌐 Microsoft Entra ID credentials use the following scopes by default:
openidoffline_accessAccessReview.ReadWrite.AllDirectory.ReadWrite.AllNetworkAccessPolicy.ReadWrite.AllDelegatedAdminRelationship.ReadWrite.AllEntitlementManagement.ReadWrite.AllUser.ReadWrite.AllDirectory.AccessAsUser.AllSites.FullControl.AllGroupMember.ReadWrite.All
要为你的凭据选择不同的权限范围,请启用 自定义权限范围 开关并编辑 启用的权限范围 列表。请记住,某些功能在权限范围更受限制的情况下可能无法正常工作。
🌐 To select different scopes for your credentials, enable the Custom Scopes slider and edit the Enabled Scopes list. Keep in mind that some features may not work as expected with more restrictive scopes.
针对整个组织的 Microsoft 集成的委托访问(Delegated access for organisation-wide Microsoft integrations)#
本节说明了 n8n 管理员如何使用委派权限注册单个 Entra ID 应用,授予一次管理员同意,然后预先配置 n8n,以便组织中的其他用户可以连接 Microsoft 服务(Outlook、Teams、OneDrive 等),而无需完成他们自己的 OAuth 应用注册。
🌐 This section explains how an n8n administrator can register a single Entra ID app with delegated permissions, grant admin consent once, and then pre-configure n8n so that other users in the organisation can connect Microsoft services (Outlook, Teams, OneDrive, and others) without completing their own OAuth app registration.
注册应用(Register the app)#
-
在 Microsoft Entra 管理中心,转到 应用注册 并选择 + 新建注册。
/// 注意 请在 应用注册 下注册,而不是 企业应用。 ///
-
为应用输入一个有意义的名称,例如
n8n Outlook。 - 在 支持的账户类型 下,选择 多个 Entra ID 租户。
- 在 仅允许某些租户(预览) 下,选择 管理允许的租户 并添加你的租户。一旦添加了你的租户,红色横幅就会消失。
- 暂时将 重定向 URI 留空,然后选择 注册。
- 在应用概览页面,复制 应用(客户端)ID。稍后你将需要它。
生成客户端密钥(Generate a client secret)#
- 在应用概览页面,选择 客户端凭据 下的 添加证书或密码。
- 选择 + 新建客户端密钥。
- 输入一个 描述(例如,
n8n token)并选择与贵组织的凭证政策相符的有效期。 - 选择 添加。
-
立即复制 值。
/// 警告 机密值只会显示一次。请在离开前复制它:否则你将无法再次获取。 ///
配置 API 权限(Configure API permissions)#
- 在左侧导航中,点击 API 权限。
- 点击 + 添加权限 > Microsoft Graph > 委派权限。
- 在 选择权限 框中,搜索每个所需的权限范围并勾选对应的框。对你希望启用的所有集成所需的权限范围重复此操作。完整列表请参阅下方的 集成所需权限范围。
- 选择 添加权限。
添加重定向 URI(Add the redirect URI)#
- 在 n8n 中,创建一个工作流,其中包含一个用于你想要配置的 Microsoft 集成的节点(例如,Microsoft Outlook)。
- 打开节点并选择 设置凭证 > 创建新凭证。
- 给凭证起一个有意义的名称(例如,
admin@yourorg.com)。 - 复制显示在 n8n 凭证面板中的 OAuth 重定向 URL。
- 回到 Entra,进入应用概览页面,在 重定向 URI 下选择 添加重定向 URI。
- 选择 + 添加重定向 URI,选择 Web,粘贴从 n8n 复制的 URL,然后选择 配置。
在 n8n 中授予管理员同意(Grant admin consent in n8n)#
- 在 n8n 中,将你之前复制的 客户端 ID 和 客户端密钥 粘贴到凭证面板中。
- 选择 连接到 [服务](例如,连接到 Microsoft Outlook)。
-
在登录弹出窗口中,勾选 代表你的组织同意,然后选择 接受。
/// 警告 你必须以管理员身份登录才能授予整个组织范围的同意。非管理员账号将看到一条消息,说明需要管理员批准。 ///
-
n8n 中的成功横幅确认连接正在工作,并且已正确授予同意。
为用户预先配置凭据(Pre-configure credentials for users)#
一旦管理员同意,请使用凭证覆盖预先配置客户端 ID 和客户端密钥,以便你组织中的用户无需自己的应用注册即可连接。有关 Docker 和 Kubernetes 设置说明,请参阅Microsoft OAuth 凭证覆盖配置指南。
🌐 Once admin consent is granted, use credential overwrites to pre-configure the Client ID and Client Secret so users in your organisation can connect without their own app registration. Refer to the Microsoft OAuth credential overwrites configuration guide for Docker and Kubernetes setup instructions.
集成所需的权限范围(Required scopes by integration)#
截至2026年3月,每个Microsoft集成都需要以下范围。在Entra中配置API权限时,请为你计划启用的每个集成添加这些范围。
🌐 The following scopes are required for each Microsoft integration as of March 2026. When configuring API permissions in Entra, add the scopes for every integration you plan to enable.
| 集成 | 所需权限 |
|---|---|
| 微软动态 | openid,offline_access |
| Microsoft Entra ID | openid、offline_access、AccessReview.ReadWrite.All、Directory.ReadWrite.All、NetworkAccessPolicy.ReadWrite.All、DelegatedAdminRelationship.ReadWrite.All、EntitlementManagement.ReadWrite.All、User.ReadWrite.All、Directory.AccessAsUser.All、Sites.FullControl.All、GroupMember.ReadWrite.All |
| 微软 Excel | openid, offline_access, Files.ReadWrite |
| Microsoft Graph 安全 | SecurityEvents.ReadWrite.All, offline_access |
| 微软 OneDrive | openid、offline_access、Files.ReadWrite.All |
| 微软 Outlook | openid、offline_access、Contacts.Read、Contacts.ReadWrite、Calendars.Read、Calendars.Read.Shared、Calendars.ReadWrite、Mail.ReadWrite、Mail.ReadWrite.Shared、Mail.Send、Mail.Send.Shared、MailboxSettings.Read |
| 微软 SharePoint | openid, offline_access |
| Microsoft Teams | openid、offline_access、User.Read.All、Group.ReadWrite.All、Chat.ReadWrite、ChannelMessage.Read.All |
| 微软待办 | openid, offline_access, Tasks.ReadWrite |
| 触发器的额外权限 | Chat.Read.All, Team.ReadBasic.All, Subscription.Read.All |
常见问题(Common issues)#
以下是 Microsoft Entra 凭据的已知常见错误和问题。
🌐 Here are the known common errors and issues with Microsoft Entra credentials.
Need admin approval#
When attempting to add credentials for a Microsoft360 or Microsoft Entra account, users may see a message when following the procedure that this action requires admin approval.
This message will appear when the account attempting to grant permissions for the credential is managed by a Microsoft Entra. In order to issue the credential, the administrator account needs to grant permission to the user (or "tenant") for that application.
The procedure for this is covered in the Microsoft Entra documentation.
在设置委派访问时需要管理员批准(Admin approval required during delegated access setup)#
如果用户看到屏幕上显示需要管理员批准,这意味着应用注册的组织范围的同意尚未被授予。
🌐 If a user sees a screen stating that admin approval is required, it means organisation-wide consent hasn't yet been granted for the app registration.
为了解决此问题,请使用 Entra ID 管理员账户完成上文中的 在 n8n 中授予管理员同意 步骤。
🌐 To resolve this, complete the Grant admin consent in n8n steps above using an Entra ID admin account.
或者,管理员可以直接在 Entra 中授予权限,而无需通过 n8n,方法是导航到:
🌐 Alternatively, an administrator can grant consent directly in Entra without going through n8n by navigating to:
企业应用 > [你的应用] > 安全 > 权限 > 为[你的组织]授予管理员同意
一旦获得同意,普通用户就可以在不遇到管理员批准提示的情况下进行身份验证。
🌐 Once consent is granted, standard users can authenticate without encountering the admin approval prompt.