合作伙伴中心身份验证

适用于:合作伙伴中心 | 由世纪互联运营的合作伙伴中心 | Microsoft Cloud for US Government 合作伙伴中心

合作伙伴中心使用 Microsoft Entra ID 进行身份验证。 与合作伙伴中心 API、SDK 或 PowerShell 模块交互时,必须正确配置 Microsoft Entra 应用程序,然后请求访问令牌。 通过“仅应用”或“应用 + 用户”身份验证获取的访问令牌可与合作伙伴中心配合使用。 但是,有两个需要考虑的重要事项

  • 使用应用 + 用户身份验证访问合作伙伴中心 API 时使用多重身份验证。 有关此更改的详细信息,请参阅启用安全应用程序模型

  • 合作伙伴中心 API 的操作中,并非所有操作都支持“仅应用”身份验证。 在某些情况下,需要使用“应用 + 用户”身份验证。 在每篇文章“先决条件”标题下,可以找到一些文档,说明是仅支持应用身份验证、应用 + 用户身份验证还是同时支持这两者。

重要

截至 2023 年 6 月 30 日,已弃用 Azure Active Directory (Azure AD) Graph。 今后,我们在 Azure AD Graph 中没有进一步的投资。 除了与安全相关的修补程序之外,Azure AD Graph API 没有 SLA 或维护承诺。 对新特性和功能的投资将仅在 Microsoft Graph 中进行。

我们将以增量步骤停用 Azure AD Graph,以便有足够的时间将应用程序迁移到 Microsoft Graph API。 稍后我们将宣布,我们将阻止使用 Azure AD Graph 创建任何新应用程序。

若要了解详细信息,请参阅 重要说明:Azure AD Graph 停用和 Powershell 模块弃用

初始设置

  1. 若要开始,需确保有一个伙伴中心主帐户和一个集成沙盒合作伙伴中心帐户。 有关详细信息,请参阅设置用于 API 访问的合作伙伴中心帐户。 记下主帐户和集成沙盒帐户的 Microsoft Entra 应用注册 ID 和机密(仅限应用标识需要客户端密码)。

  2. 从Azure 门户登录到 Microsoft Entra ID。 在“对其他应用程序的权限”中,将 Windows Azure Active Directory 的权限设置为“委托权限”,并选择“以已登录用户的身份访问目录”和“登录并读取用户配置文件”

  3. 在 Azure 门户中,选择“添加应用程序”。 搜索“Microsoft 合作伙伴中心”,这是 Microsoft 合作伙伴中心应用程序。 将“委托权限”设置为“访问合作伙伴中心 API”。 如果使用适用于美国政府的 Microsoft 云合作伙伴中心,则此步骤是必需的。 如果使用合作伙伴中心全局实例,则此步骤是可选的。 CSP 合作伙伴可以使用合作伙伴中心中的应用管理功能来绕过合作伙伴中心全局实例的此步骤。

“仅应用”身份验证

若要使用“仅应用”身份验证来访问合作伙伴中心 REST API、.NET API、Java API 或 PowerShell 模块,则可按照以下说明来实现此目的。

.NET(“仅应用”身份验证)

public static IAggregatePartner GetPartnerCenterTokenUsingAppCredentials()
{
    IPartnerCredentials partnerCredentials =
        PartnerCredentials.Instance.GenerateByApplicationCredentials(
            PartnerApplicationConfiguration.ApplicationId,
            PartnerApplicationConfiguration.ApplicationSecret,
            PartnerApplicationConfiguration.ApplicationDomain);

    // Create operations instance with partnerCredentials.
    return PartnerService.Instance.CreatePartnerOperations(partnerCredentials);
}

Java(“仅应用”身份验证)

合作伙伴中心 Java SDK 可用于管理合作伙伴中心资源。 它是由合作伙伴社区维护的开源项目,不受 Microsoft 正式支持。 如果遇到问题,可以从社区获取帮助在 GitHub 上创建问题

public IAggregatePartner getAppPartnerOperations()
{
    IPartnerCredentials appCredentials =
        PartnerCredentials.getInstance().generateByApplicationCredentials(
        PartnerApplicationConfiguration.getApplicationId(),
        PartnerApplicationConfiguration.getApplicationSecret(),
        PartnerApplicationConfiguration.getApplicationDomain());

    return PartnerService.getInstance().createPartnerOperations( appCredentials );
}

REST(“仅应用”身份验证)

REST 请求

POST https://login.microsoftonline.com/{tenantId}/oauth2/token HTTP/1.1
Accept: application/json
return-client-request-id: true
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: login.microsoftonline.com
Content-Length: 194
Expect: 100-continue

resource=https%3A%2F%2Fgraph.windows.net&client_id={client-id-here}&client_secret={client-secret-here}&grant_type=client_credentials

REST 响应

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Content-Length: 1406

{"token_type":"Bearer","expires_in":"3600","ext_expires_in":"3600","expires_on":"1546469802","not_before":"1546465902","resource":"https://graph.windows.net","access_token":"value-has-been-removed"}

“应用 + 用户”身份验证

以前一直在使用资源所有者密码凭据授予来请求可以与合作伙伴中心 REST API、.NET API、Java API 或 PowerShell 模块配合使用的访问令牌。 该方法用于使用客户端标识符和用户凭据从 Microsoft Entra ID 请求访问令牌。 但是,此方法将不再有效,因为合作伙伴中心在使用应用 + 用户身份验证时需要多重身份验证。 为了遵守这一要求,Microsoft 引入了一个安全的、可缩放的框架,用于使用多重身份验证对云解决方案提供商(CSP)合作伙伴和控制面板供应商(CPV)进行身份验证。 此框架称为安全应用程序模型,它由同意过程和使用刷新令牌的访问令牌请求组成。

合作伙伴同意过程是一个交互式过程,其中合作伙伴使用多重身份验证进行身份验证、对应用程序的同意,并且刷新令牌存储在安全存储库(如 Azure 密钥库)中。 建议将专用于集成的帐户用于此过程。

重要

应为合作伙伴许可过程中使用的服务帐户启用适当的多重身份验证解决方案。 否则,生成的刷新令牌会不符合安全要求。

“应用 + 用户”身份验证示例

合作伙伴同意过程可以通过多种方式执行。 为了帮助合作伙伴了解如何执行每个必需的操作,我们开发了以下示例。 在环境中实施适当的解决方案时,请务必开发一个解决方案,该解决方案与编码标准和安全策略一起投诉。

.NET(“应用+用户”身份验证)

合作伙伴许可示例项目演示了如何利用通过 ASP.NET 开发的网站来捕获许可、请求刷新令牌并将其安全地存储在 Azure Key Vault 中。 请执行以下步骤,为本示例创建所需的先决条件。

  1. 使用 Azure 门户或以下 PowerShell 命令创建 Azure Key Vault 的实例。 执行命令前,请确保相应地修改参数值。 保管库名称必须独一无二。

    Login-AzureRmAccount
    
    # Create a new resource group
    New-AzureRmResourceGroup -Name ContosoResourceGroup -Location EastUS
    
    New-AzureRmKeyVault -Name 'Contoso-Vault' -ResourceGroupName 'ContosoResourceGroup' -Location 'East US'
    

    有关创建 Azure 密钥库的详细信息,请参阅快速入门:使用 Azure 门户快速入门设置和检索 Azure 密钥库中的机密:使用 PowerShell 从 Azure 密钥库设置和检索机密。 然后设置并检索机密。

  2. 使用Azure 门户或以下命令创建 Microsoft Entra 应用程序和密钥。

    Connect-MgGraph -Scopes "Application.ReadWrite.OwnedBy"
    
    $Context = Get-MgContext
    
    $app = New-MgApplication -DisplayName 'My Vault Access App' -Web @{ RedirectUris = 'https://$($Context.TenantId)/$((New-Guid).ToString())' }
    $password = Add-MgApplicationPassword -ApplicationId $app.AppId
    
    Write-Host "ApplicationId       = $($app.AppId)"
    Write-Host "ApplicationSecret   = $($password.SecretText)"
    

    请确保记下应用程序标识符和机密值,因为在下面的步骤中会用到它们。

  3. 使用Azure 门户或以下命令向新创建的 Microsoft Entra 应用程序授予读取机密权限。

    # Connect to Microsoft Graph
    Connect-MgGraph -Scopes "User.Read"
    
    # Get the application
    $app = Get-MgApplication -Filter "appId eq 'ENTER-APP-ID-HERE'"
    
    # Set the Key Vault access policy
    Set-AzKeyVaultAccessPolicy -VaultName ContosoVault -ObjectId $app.Id -PermissionsToSecrets get
    
  4. 创建为合作伙伴中心配置的 Microsoft Entra 应用程序。 执行以下操作,完成此步骤。

    请确保记录应用 ID、帐户 ID*和密钥值,因为在下面的步骤中会用到它们。

  5. 使用 Visual Studio 或以下命令克隆 Partner-Center-DotNet-Samples 存储库。

    git clone https://github.com/Microsoft/Partner-Center-DotNet-Samples.git
    
  6. 打开在 Partner-Center-DotNet-Samples\secure-app-model\keyvault 目录中找到的 PartnerConsent 项目。

  7. 填充在 web.config 中找到的应用程序设置

    <!-- AppID that represents CSP application -->
    <add key="ida:CSPApplicationId" value="" />
    <!--
        Please use certificate as your client secret and deploy the certificate to your environment.
        The following application secret is for sample application only. please do not use secret directly from the config file.
    -->
    <add key="ida:CSPApplicationSecret" value="" />
    
    <!--
        Endpoint address for the instance of Azure KeyVault. This is
        the DNS Name for the instance of Key Vault that you provisioned.
     -->
    <add key="KeyVaultEndpoint" value="" />
    
    <!-- App ID that is given access for KeyVault to store refresh tokens -->
    <add key="ida:KeyVaultClientId" value="" />
    
    <!--
        Please use certificate as your client secret and deploy the certificate
        to your environment. The following application secret is for sample
        application only. please do not use secret directly from the config file.
    -->
    <add key="ida:KeyVaultClientSecret" value="" />
    

    重要

    敏感信息(如应用程序机密)不应存储在配置文件中。 在这里这样做是因为这是一个示例应用程序。 对于生产应用程序,强烈建议使用基于证书的身份验证。 有关详细信息,请参阅用于应用程序身份验证的证书凭据

  8. 运行此示例项目时,它会提示你进行身份验证。 成功进行身份验证后,会从 Microsoft Entra ID 请求访问令牌。 从 Microsoft Entra ID 返回的信息包括存储在 Azure 密钥库配置的实例中的刷新令牌。

Java(“应用+用户”身份验证)

合作伙伴许可示例项目演示了如何利用通过 JSP 开发的网站来捕获许可、请求刷新令牌并将其安全地存储在 Azure Key Vault 中。 请执行以下步骤,为本示例创建所需的先决条件。

  1. 使用 Azure 门户或以下 PowerShell 命令创建 Azure Key Vault 的实例。 执行命令前,请确保相应地修改参数值。 保管库名称必须独一无二。

    Login-AzureRmAccount
    
    # Create a new resource group
    New-AzureRmResourceGroup -Name ContosoResourceGroup -Location EastUS
    
    New-AzureRmKeyVault -Name 'Contoso-Vault' -ResourceGroupName 'ContosoResourceGroup' -Location 'East US'
    

    有关创建 Azure 密钥库的详细信息,请参阅快速入门:使用 Azure 门户快速入门设置和检索 Azure 密钥库中的机密:使用 PowerShell 从 Azure 密钥库设置和检索机密。

  2. 使用Azure 门户或以下命令创建 Microsoft Entra 应用程序和密钥。

    Connect-MgGraph -Scopes "Application.ReadWrite.OwnedBy"
    
    $Context = Get-MgContext
    
    $app = New-MgApplication -DisplayName 'My Vault Access App' -IdentifierUri 'https://$($Context.TenantDomain)/$((New-Guid).ToString())'
    $password = Add-MgApplicationPassword -ApplicationId $app.AppId
    
    Write-Host "ApplicationId       = $($app.AppId)"
    Write-Host "ApplicationSecret   = $($password.SecretText)"
    

    请确保记录应用程序标识符和机密值,因为在下面的步骤中会用到它们。

  3. 使用Azure 门户或以下命令向新创建的 Microsoft Entra 应用程序授予读取机密权限。

    Connect-MgGraph -Scopes "User.Read"
    $app = Get-MgApplication -Filter "appId eq 'ENTER-APP-ID-HERE'"
    
    Set-AzKeyVaultAccessPolicy -VaultName ContosoVault -ObjectId $app.Id -PermissionsToSecrets get
    
  4. 创建为合作伙伴中心配置的 Microsoft Entra 应用程序。 执行以下操作,完成此步骤。

    请确保记录应用 ID、帐户 ID*和密钥值,因为在下面的步骤中会用到它们。

  5. 使用以下命令克隆 Partner-Center-Java-Samples 存储库

    git clone https://github.com/Microsoft/Partner-Center-Java-Samples.git
    
  6. 打开在 Partner-Center-Java-Samples\secure-app-model\keyvault 目录中找到的 PartnerConsent 项目。

  7. 填充在 web.xml 文件中找到的应用程序设置

    <filter>
        <filter-name>AuthenticationFilter</filter-name>
        <filter-class>com.microsoft.store.samples.partnerconsent.security.AuthenticationFilter</filter-class>
        <init-param>
            <param-name>client_id</param-name>
            <param-value></param-value>
        </init-param>
        <init-param>
            <param-name>client_secret</param-name>
            <param-value></param-value>
        </init-param>
        <init-param>
            <param-name>keyvault_base_url</param-name>
            <param-value></param-value>
        </init-param>
        <init-param>
            <param-name>keyvault_client_id</param-name>
            <param-value></param-value>
        </init-param>
        <init-param>
            <param-name>keyvault_client_secret</param-name>
            <param-value></param-value>
        </init-param>
        <init-param>
            <param-name>keyvault_certifcate_path</param-name>
            <param-value></param-value>
        </init-param>
    </filter>
    

    重要

    敏感信息(如应用程序机密)不应存储在配置文件中。 在这里这样做是因为这是一个示例应用程序。 对于生产应用程序,强烈建议使用基于证书的身份验证。 有关详细信息,请参阅 Key Vault 证书身份验证

  8. 运行此示例项目时,它会提示你进行身份验证。 成功进行身份验证后,会从 Microsoft Entra ID 请求访问令牌。 从 Microsoft Entra ID 返回的信息包括存储在 Azure 密钥库配置的实例中的刷新令牌。

云解决方案提供商身份验证

云解决方案提供商合作伙伴可以使用通过合作伙伴许可过程获得的刷新令牌。

云解决方案提供商身份验证示例

为了帮助合作伙伴了解如何执行每个必需的操作,我们开发了以下示例。 在环境中实施适当的解决方案时,请务必开发一个解决方案,该解决方案与编码标准和安全策略一起投诉。

.NET(CSP 身份验证)

  1. 如果尚未执行此操作,请执行 合作伙伴同意过程

  2. 使用 Visual Studio 或以下命令克隆 Partner-Center-DotNet-Samples 存储库

    git clone https://github.com/Microsoft/Partner-Center-DotNet-Samples.git
    
  3. 打开在 Partner-Center-DotNet-Samples\secure-app-model\keyvault 目录中找到的 CSPApplication 项目。

  4. 更新在 App.config 文件中找到的应用程序设置。

    <!-- AppID that represents CSP application -->
    <add key="ida:CSPApplicationId" value="" />
    <!--
        Please use certificate as your client secret and deploy the certificate to your environment.
        The following application secret is for sample application only. please do not use secret directly from the config file.
    -->
    <add key="ida:CSPApplicationSecret" value="" />
    
    <!-- Endpoint address for the instance of Azure KeyVault -->
    <add key="KeyVaultEndpoint" value="" />
    
    <!-- AppID that is given access for keyvault to store the refresh tokens -->
    <add key="ida:KeyVaultClientId" value="" />
    
    <!--
        Please use certificate as your client secret and deploy the certificate to your environment.
        The following application secret is for sample application only. please do not use secret directly from the config file.
    -->
    <add key="ida:KeyVaultClientSecret" value="" />
    
  5. 为在 Program.cs 文件中发现的 PartnerIdCustomerId 变量设置适当的值。

    // The following properties indicate which partner and customer context the calls are going to be made.
    string PartnerId = "<Partner tenant id>";
    string CustomerId = "<Customer tenant id>";
    
  6. 运行此示例项目时,它会获取在合作伙伴许可过程中获取的刷新令牌。 然后,它会请求一个代表合作伙伴与合作伙伴中心 SDK 交互的访问令牌。 最后,它会请求一个代表指定的客户与 Microsoft Graph 交互的访问令牌。

Java(CSP 身份验证)

  1. 如果尚未执行此操作,请执行 合作伙伴同意过程

  2. 使用 Visual Studio 或以下命令克隆 Partner-Center-Java-Samples 存储库

    git clone https://github.com/Microsoft/Partner-Center-Java-Samples.git
    
  3. 打开在 Partner-Center-Java-Samples\secure-app-model\keyvault 目录中找到的 cspsample 项目。

  4. 更新在 application.properties 文件中找到的应用程序设置。

    azuread.authority=https://login.microsoftonline.com
    keyvault.baseurl=
    keyvault.clientId=
    keyvault.clientSecret=
    partnercenter.accountId=
    partnercenter.clientId=
    partnercenter.clientSecret=
    
  5. 运行此示例项目时,它会获取在合作伙伴许可过程中获取的刷新令牌。 然后,它会请求一个代表合作伙伴与合作伙伴中心 SDK 交互的访问令牌。

  6. 可选 - 若要了解如何代表客户与 Azure 资源管理器和 Microsoft Graph 交互,请取消注释 RunAzureTask 和 RunGraphTask 函数调用。

控制面板提供商身份验证

控制面板供应商需要让其支持的每个合作伙伴都执行合作伙伴许可过程。 完成该操作后,需使用通过该过程获取的刷新令牌来访问合作伙伴中心 REST API 和 .NET API。

注意

控制面板供应商应至少具有客户租户中的云应用程序管理员角色。

云面板提供商身份验证示例

为了帮助控制面板供应商了解如何执行每个必需的操作,我们开发了以下示例。 在环境中实施适当的解决方案时,请务必开发一个解决方案,该解决方案与编码标准和安全策略一起投诉。

.NET(CPV 身份验证)

  1. 为云解决方案提供商合作伙伴开发和部署提供相应许可所需的流程。 有关详细信息及示例,请参阅合作伙伴同意

    重要

    不应存储来自云解决方案提供商合作伙伴的用户凭据。 应该存储通过合作伙伴许可过程获得的刷新令牌,并使用该令牌来请求与任何 Microsoft API 交互所需的访问令牌。

  2. 使用 Visual Studio 或以下命令克隆 Partner-Center-DotNet-Samples 存储库

    git clone https://github.com/Microsoft/Partner-Center-DotNet-Samples.git
    
  3. 打开在 Partner-Center-DotNet-Samples\secure-app-model\keyvault 目录中找到的 CPVApplication 项目。

  4. 更新在 App.config 文件中找到的应用程序设置。

    <!-- AppID that represents Control panel vendor application -->
    <add key="ida:CPVApplicationId" value="" />
    
    <!--
        Please use certificate as your client secret and deploy the certificate to your environment.
        The following application secret is for sample application only. please do not use secret directly from the config file.
    -->
    <add key="ida:CPVApplicationSecret" value="" />
    
    <!-- Endpoint address for the instance of Azure KeyVault -->
    <add key="KeyVaultEndpoint" value="" />
    
    <!-- AppID that is given access for keyvault to store the refresh tokens -->
    <add key="ida:KeyVaultClientId" value="" />
    
    <!--
        Please use certificate as your client secret and deploy the certificate to your environment.
        The following application secret is for sample application only. please do not use secret directly from the config file.
    -->
    <add key="ida:KeyVaultClientSecret" value="" />
    
  5. 为在 Program.cs 文件中发现的 PartnerIdCustomerId 变量设置适当的值。

    // The following properties indicate which partner and customer context the calls are going to be made.
    string PartnerId = "<Partner tenant id>";
    string CustomerId = "<Customer tenant id>";
    
  6. 运行此示例项目时,它会获取指定合作伙伴的刷新令牌。 然后,它会请求一个代表合作伙伴访问合作伙伴中心和 Microsoft Graph 的访问令牌。 它执行的下一个任务是删除和创建授予客户租户的权限。 由于控制面板供应商和客户之间不存在任何关系,因此需要使用合作伙伴中心 API 添加这些权限。 以下示例演示如何完成此操作。

    JObject contents = new JObject
    {
        // Provide your application display name
        ["displayName"] = "CPV Marketplace",
    
        // Provide your application id
        ["applicationId"] = CPVApplicationId,
    
        // Provide your application grants
        ["applicationGrants"] = new JArray(
            JObject.Parse("{\"enterpriseApplicationId\": \"00000003-0000-0000-c000-000000000000\", \"scope\":\"Domain.ReadWrite.All,User.ReadWrite.All,Directory.Read.All\"}"), // for Microsoft Graph access,  Directory.Read.All
            JObject.Parse("{\"enterpriseApplicationId\": \"797f4846-ba00-4fd7-ba43-dac1f8f63013\", \"scope\":\"user_impersonation\"}")) // for Azure Resource Manager access
    };
    
    /**
     * The following steps have to be performed once per customer tenant if your application is
     * a control panel vendor application and requires customer tenant Microsoft Graph access.
     **/
    
    // delete the previous grant into customer tenant
    JObject consentDeletion = await ApiCalls.DeleteAsync(
        tokenPartnerResult.Item1,
        string.Format("https://api.partnercenter.microsoft.com/v1/customers/{0}/applicationconsents/{1}", CustomerId, CPVApplicationId));
    
    // create new grants for the application given the setting in application grants payload.
    JObject consentCreation = await ApiCalls.PostAsync(
        tokenPartnerResult.Item1,
        string.Format("https://api.partnercenter.microsoft.com/v1/customers/{0}/applicationconsents", CustomerId),
        contents.ToString());
    

在建立这些权限后,该示例将使用 Microsoft Graph 代表客户执行操作。

注意

有关 Microsoft Graph 的详细信息,请参阅 Microsoft Graph 概述

Java(CPV 身份验证)

  1. 为云解决方案提供商合作伙伴开发和部署提供相应许可所需的流程。 有关详细信息和示例,请参阅合作伙伴同意

    重要

    不应存储来自云解决方案提供商合作伙伴的用户凭据。 应该存储通过合作伙伴许可过程获得的刷新令牌,并使用该令牌来请求与任何 Microsoft API 交互所需的访问令牌。

  2. 使用以下命令克隆 Partner-Center-Java-Samples 存储库

    git clone https://github.com/Microsoft/Partner-Center-Java-Samples.git
    
  3. 打开在 Partner-Center-Java-Samples\secure-app-model\keyvault 目录中找到的 cpvsample 项目。

  4. 更新在 application.properties 文件中找到的应用程序设置。

    azuread.authority=https://login.microsoftonline.com
    keyvault.baseurl=
    keyvault.clientId=
    keyvault.clientSecret=
    partnercenter.accountId=
    partnercenter.clientId=
    partnercenter.clientSecret=
    partnercenter.displayName=
    

    partnercenter.displayName 的值应该是商城应用程序的显示名称。

  5. 为在 Program.java 文件中发现的 partnerIdcustomerId 变量设置适当的值。

    partnerId = "SPECIFY-THE-PARTNER-TENANT-ID-HERE";
    customerId = "SPECIFY-THE-CUSTOMER-TENANT-ID-HERE";
    
  6. 运行此示例项目时,它会获取指定合作伙伴的刷新令牌。 然后,它会请求一个代表合作伙伴访问合作伙伴中心的访问令牌。 它执行的下一个任务是删除和创建授予客户租户的权限。 由于控制面板供应商和客户之间不存在任何关系,因此需要使用合作伙伴中心 API 添加这些权限。 以下示例演示了如何授予权限。

    ApplicationGrant azureAppGrant = new ApplicationGrant();
    
    azureAppGrant.setEnterpriseApplication("797f4846-ba00-4fd7-ba43-dac1f8f63013");
    azureAppGrant.setScope("user_impersonation");
    
    ApplicationGrant graphAppGrant = new ApplicationGrant();
    
    graphAppGrant.setEnterpriseApplication("00000002-0000-0000-c000-000000000000");
    graphAppGrant.setScope("Domain.ReadWrite.All,User.ReadWrite.All,Directory.Read.All");
    
    ApplicationConsent consent = new ApplicationConsent();
    
    consent.setApplicationGrants(Arrays.asList(azureAppGrant, graphAppGrant));
    consent.setApplicationId(properties.getProperty(PropertyName.PARTNER_CENTER_CLIENT_ID));
    consent.setDisplayName(properties.getProperty(PropertyName.PARTNER_CENTER_DISPLAY_NAME));
    
    // Deletes the existing grant into the customer it is present.
    partnerOperations.getServiceClient().delete(
        partnerOperations,
        new TypeReference<ApplicationConsent>(){},
        MessageFormat.format(
            "customers/{0}/applicationconsents/{1}",
            customerId,
            properties.getProperty(PropertyName.PARTNER_CENTER_CLIENT_ID)));
    
    // Consent to the defined applications and the respective scopes.
    partnerOperations.getServiceClient().post(
        partnerOperations,
        new TypeReference<ApplicationConsent>(){},
        MessageFormat.format(
            "customers/{0}/applicationconsents",
            customerId),
        consent);
    

若要了解如何代表客户与 Azure 资源管理器和 Microsoft Graph 交互,请取消注释 RunAzureTask 和 RunGraphTask 函数调用。