在 Google Workspace 和 Microsoft Entra ID 之间配置联合

本文介绍将 Google Workspace 配置为标识提供者 (idP) Microsoft Entra ID所需的步骤。
配置后,用户可以使用其 Google 工作区凭据登录到Microsoft Entra ID。

必备条件

若要将 Google Workspace 配置为 Microsoft Entra ID 的 IdP,必须满足以下先决条件:

  1. Microsoft Entra租户,具有一个或多个自定义 DNS 域 (即格式不为 *.onmicrosoft.com 的域)
  2. 使用具有全局管理员角色的帐户访问Microsoft Entra ID
  3. 使用具有 超级管理员 权限的帐户访问 Google 工作区

若要测试联合身份验证,必须满足以下先决条件:

  1. 已创建用户的 Google 工作区环境

    重要提示

    用户需要在 Google Workspace 中定义电子邮件地址,该地址用于匹配 Microsoft Entra ID 中的用户。 有关标识匹配的详细信息,请参阅 Microsoft Entra ID 中的标识匹配

  2. 已创建的各个Microsoft Entra帐户:每个 Google Workspace 用户都需要Microsoft Entra ID中定义的匹配帐户。 这些帐户通常通过自动化解决方案创建,例如:
    • 学校数据同步 (SDS)
    • Microsoft Entra使用本地 AD DS 连接环境同步
    • 调用 Microsoft 图形 API的 PowerShell 脚本
    • IdP 提供的预配工具 - Google 工作区提供 自动预配

将 Google Workspace 配置为 Microsoft Entra ID 的 IdP

  1. 使用具有超级管理员权限的帐户登录到 Google 工作区管理员控制台

  2. 选择 “应用” > “Web 和移动应用”

  3. 选择“为应用添加应用>搜索”并搜索 microsoft

  4. 在搜索结果页中,将鼠标悬停在“Microsoft Office 365 - Web (SAML) 应用”上,然后选择“选择屏幕截图”,其中显示了“Google 工作区”和“Microsoft Office 365 SAML 应用的搜索”按钮。

  5. “Google 标识提供者详细信息”页上,选择“下载元数据”,并记下 IdP 元数据 - GoogleIDPMetadata.xml 保存位置 - 文件,因为稍后将用于设置Microsoft Entra ID

  6. “服务提供商详细信息 ”页上

    • 选择选项 “签名的响应”
    • 验证名称 ID 格式是否设置为 PERSISTENT
    • 根据Microsoft Entra ID中预配Microsoft Entra用户的方式,可能需要调整名称 ID 映射。
      如果使用 Google 自动预配,请选择“基本信息>主电子邮件
    • 选择“ 继续”
  7. “属性映射”页上,将 Google 属性映射到Microsoft Entra属性

    Google Directory 属性 Microsoft Entra属性
    基本信息:主要Email 应用属性:IDPEmail

    重要提示

    必须确保你的用户帐户电子邮件与 Google 工作区中的用户帐户匹配Microsoft Entra。

  8. 选择“完成

配置应用后,必须在 Google Workspace 中为用户启用它:

  1. 使用具有超级管理员权限的帐户登录到 Google 工作区管理员控制台
  2. 选择 “应用” > “Web 和移动应用”
  3. 选择Microsoft Office 365
  4. 选择 “用户访问”
  5. 为所有人>“保存”选择“打开”

将 Microsoft Entra ID 配置为 Google Workspace 的服务提供商 (SP)

Microsoft Entra ID的配置包括更改自定义 DNS 域的身份验证方法。 可以使用 PowerShell 完成此配置。
使用从 Google Workspace 下载的 IdP 元数据 XML 文件,修改以下脚本的 $DomainName 变量以匹配环境,然后在 PowerShell 会话中运行它。 当系统提示向Microsoft Entra ID进行身份验证时,请使用具有全局管理员角色的帐户的凭据。

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Install-Module Microsoft.Graph -Scope CurrentUser
Import-Module Microsoft.Graph

$domainId = "<your domain name>"

$xml = [Xml](Get-Content GoogleIDPMetadata.xml)

$cert = -join $xml.EntityDescriptor.IDPSSODescriptor.KeyDescriptor.KeyInfo.X509Data.X509Certificate.Split()
$issuerUri = $xml.EntityDescriptor.entityID
$signinUri = $xml.EntityDescriptor.IDPSSODescriptor.SingleSignOnService | ? { $_.Binding.Contains('Redirect') } | % { $_.Location }
$signoutUri = "https://accounts.google.com/logout"
$displayName = "Google Workspace Identity"
Connect-MGGraph -Scopes "Domain.ReadWrite.All", "Directory.AccessAsUser.All"

$domainAuthParams = @{
  DomainId = $domainId
  IssuerUri = $issuerUri
  DisplayName = $displayName
  ActiveSignInUri = $signinUri
  PassiveSignInUri = $signinUri
  SignOutUri = $signoutUri
  SigningCertificate = $cert
  PreferredAuthenticationProtocol = "saml"
  federatedIdpMfaBehavior = "acceptIfMfaDoneByFederatedIdp"
}

New-MgDomainFederationConfiguration @domainAuthParams

若要验证配置是否正确,可以使用以下 PowerShell 命令:

Get-MgDomainFederationConfiguration -DomainId $domainId |fl
ActiveSignInUri                       : https://accounts.google.com/o/saml2/idp?idpid=<GUID>
DisplayName                           : Google Workspace Identity
FederatedIdpMfaBehavior               : acceptIfMfaDoneByFederatedIdp
Id                                    : 3f600dce-ab37-4798-9341-ffd34b147f70
IsSignedAuthenticationRequestRequired :
IssuerUri                             : https://accounts.google.com/o/saml2?idpid=<GUID>
MetadataExchangeUri                   :
NextSigningCertificate                :
PassiveSignInUri                      : https://accounts.google.com/o/saml2/idp?idpid=<GUID>
PreferredAuthenticationProtocol       : saml
PromptLoginBehavior                   :
SignOutUri                            : https://accounts.google.com/logout
SigningCertificate                    : <BASE64 encoded certificate>
AdditionalProperties                  : {}

验证 Google Workspace 与 Microsoft Entra ID 之间的联合身份验证

在专用浏览器会话中,导航到 https://portal.azure.com 并使用 Google 工作区帐户登录:

  1. 使用 Google Workspace 中定义的电子邮件作为用户名
  2. 用户被重定向到 Google Workspace 以登录
  3. Google 工作区身份验证后,用户被重定向回Microsoft Entra ID并登录

显示用户使用 Google Workspace 联合标识对Azure 门户进行身份验证的 GIF。