在 Microsoft Entra ID 中更改子域身份验证类型

将根域添加到属于 Microsoft Entra 的 Microsoft Entra ID 后,Microsoft Entra 组织中添加到该根的所有后续子域都将自动从根域继承身份验证设置。 但是,如果要独立于根域设置来管理域身份验证设置,现在可以使用 Microsoft Graph API 来实现。 例如,如果你有一个联合根域(如 contoso.com),则本文可以帮助你将子域(如 child.contoso.com)验证为托管子域而非联合子域。

在 Azure 门户中,当父域已联合并且管理员尝试验证“自定义域名”页面上的托管子域时,页面显示“无法添加域”错误,原因是“一个或多个属性包含无效值”。如果尝试从 Microsoft 365 管理中心添加此子域,将收到类似错误。 有关错误的详细信息,请参阅子域不继承 Office 365、Azure 或 Intune 中的父域更改

因为默认情况下子域继承根域的身份验证类型,因此必须使用 Microsoft Graph 将子域升级为 Microsoft Entra ID 中的根域,才能将身份验证类型设置为所需的类型。

警告

此示例代码用于演示目的。 如果想要在环境中使用,请考虑先进行小规模的测试,或者在单独的测试组织中测试。 可能需要根据具体的环境需求调整该代码。

添加子域

  1. 使用 PowerShell 添加新子域,该子域具有其根域的默认身份验证类型。 Microsoft Entra ID 和 Microsoft 365 管理中心尚不支持此操作。

    # Connect to Microsoft Graph with the required scopes
    Connect-MgGraph -Environment China -ClientId 'YOUR_CLIENT_ID' -TenantId 'YOUR_TENANT_ID' -Scopes "Domain.ReadWrite.All"
    
    # Define the parameters for the new domain
    $domainParams = @{
        Name = "child6.mydomain.com"
        AuthenticationType = "Federated"
    }
    
    # Create a new domain with the specified parameters
    New-MgDomain @domainParams

  1. 使用以下示例通过 GET 获取域。 因为该域不是根域,所以它继承了根域身份验证类型。 使用你自己的租户 ID,命令和结果可能如下所示:

    GET https://microsoftgraph.chinacloudapi.cn/v1.0/domains/foo.contoso.com/
    
    Return:
      {
          "authenticationType": "Federated",
          "availabilityStatus": null,
          "isAdminManaged": true,
          "isDefault": false,
          "isDefaultForCloudRedirections": false,
          "isInitial": false,
          "isRoot": false,          <---------------- Not a root domain, so it inherits parent domain's authentication type (federated)
          "isVerified": true,
          "name": "child.mydomain.com",
          "supportedServices": [],
          "forceDeleteState": null,
          "state": null,
          "passwordValidityPeriodInDays": null,
          "passwordNotificationWindowInDays": null
      },
    

将子域更改为根域

使用以下命令升级子域:

POST https://microsoftgraph.chinacloudapi.cn/v1.0/{tenant-id}/domains/foo.contoso.com/promote

提升命令错误条件

场景 方法 代码 Message
使用未验证父域的子域调用 API POST 400 无法提升未验证的域。 请在提升前验证域。
使用具有用户引用的联合验证子域调用 API POST 400 不允许提升具有用户引用的子域。 请在提升子域之前将用户迁移到当前根域。

更改要管理的子域身份验证类型

重要

若要更改联合子域的身份验证类型,应在完成以下步骤之前记下现有的联合配置值。 如果你决定在提升域之前重新实施联合身份验证,则可能需要此信息。

  1. 使用以下命令更改子域身份验证类型:

    Connect-MgGraph -Environment China -ClientId 'YOUR_CLIENT_ID' -TenantId 'YOUR_TENANT_ID' -Scopes "Domain.ReadWrite.All", "Directory.AccessAsUser.All"
    Update-MgDomain -DomainId "test.contoso.com" -BodyParameter @{AuthenticationType="Managed"}
    
  2. 在 Microsoft Graph API 中通过 GET 验证现在是否已管理子域身份验证类型:

    GET https://microsoftgraph.chinacloudapi.cn/v1.0/domains/foo.contoso.com/
    
    Return:
      {
          "authenticationType": "Managed",   <---------- Now this domain is successfully added as Managed and not inheriting Federated status
          "availabilityStatus": null,
          "isAdminManaged": true,
          "isDefault": false,
          "isDefaultForCloudRedirections": false,
          "isInitial": false,
          "isRoot": true,   <------------------------------ Also a root domain, so not inheriting from parent domain any longer
          "isVerified": true,
          "name": "child.mydomain.com",
          "supportedServices": [
              "Email",
              "OfficeCommunicationsOnline",
              "Intune"
          ],
          "forceDeleteState": null,
          "state": null,
          "passwordValidityPeriodInDays": null,
          "passwordNotificationWindowInDays": null }
    

后续步骤