创建安全合作伙伴应用程序
可以通过为云解决方案提供商 (CSP) 创建应用程序,或控制面板供应商 (CPV) 来实现安全应用程序模型框架。
创建合作伙伴中心服务主体
首先,在要在其中创建多租户应用程序的云解决方案提供商合作伙伴租户中创建 Microsoft 合作伙伴中心服务主体。
对于云解决方案提供商合作伙伴租户,此服务主体应已存在。 如果没有,请使用以下步骤创建。
在管理员 PowerShell 窗口中运行以下命令。
- 安装 AzureAD 模块。
Install-Module "AzureAD" - 运行 连接-AzureAD,这将提示输入用户名和密码。 输入租户管理员凭据。
Connect-AzureAD - 创建 Microsoft 合作伙伴中心服务主体。
New-AzureADServicePrincipal -DisplayName "Microsoft Partner Center" -AppId fa3d9a0c-3fb0-42cc-9193-47c7ecd2edbd
在云解决方案提供商合作伙伴的租户中创建多租户应用程序
使用以下步骤确保为新建的多租户应用程序设置以下应用程序属性。
- 登录 portal.azure.com
- 选择Azure Active Directory和应用注册以使用多租户创建新注册。
- 为应用程序选择面向用户的显示名称。
- 选择受支持的帐户类型:任何组织目录中的帐户 (任何 Azure AD 目录 - 多租户) 。
- 选择 平台 类型“Web”。
- 重定向 URL 必须是应用程序重定向 URL,这会向合作伙伴显示同意成功消息并收集刷新令牌。 确保应用的重定向 URL 设置为运行实时 Web 应用的终结点。 此应用需要接受 Azure AD 登录调用中的 授权代码 。
- 转到“客户端机密”选项卡中 的“管理>证书 & 机密>+新建客户端密码 ”。
注意
请注意 Azure AD 中 Web 应用的设置中的以下信息:
- 应用程序 ID
- 应用程序机密
应用权限
请确保为多租户应用程序设置以下权限。
在 API 权限 部分中:
- 不应有对多租户应用程序的任何直接 应用程序权限 。
- 按照以下路径添加 Microsoft Graph的委派权限
- API 权限>添加权限>Microsoft API>Microsoft Graph>Delegated 权限
DelegatedAdminRelationship.ReadWrite.All User.Read.All
- API 权限>添加权限>Microsoft API>Microsoft Graph>Delegated 权限
- 按照以下路径为 Microsoft 合作伙伴中心添加委派权限 - 在“委派权限”下授予访问合作伙伴中心权限
- API 权限>添加权限>我的组织使用的> APIMicrosoft 合作伙伴中心>委派的权限>用户模拟
提供同意链接
向合作伙伴提供同意链接,并让他们使用其服务帐户登录,以批准应用程序代表合作伙伴租户的服务帐户采取行动。
云解决方案提供商合作伙伴用户必须是全局管理员和管理员代理才能同意多租户应用程序。
多租户应用程序
需要将多租户 ApplicationID 替换为应用程序 ID。
导航到 应用注册 ,然后选择应用程序 (客户端) ID,并替换以下 ID。
获取授权代码
必须从 Azure AD 登录调用获取 Web 应用的授权代码:
- 登录到 Azure AD。
- 将 Application-Id 替换为你的 Azure AD 应用 ID (GUID)。
- 出现提示时,请使用配置 MFA 的用户帐户登录。
- 出现提示时,输入其他 MFA 信息 (电话号码或电子邮件地址) 以验证登录。
- 登录后,浏览器将使用授权代码将调用重定向到 Web 应用终结点。 例如,以下示例代码会将调用重定向到
https://localhost:44395/。
GET https://login.microsoftonline.com/common/oauth2/authorize?&client_id=<CSPApplicationId>&response_type=code&redirect_url=https://<CSPApplicationUrl_which_collects_refreshtoken>
或
GET https://login.microsoftonline.com/common/oauth2/authorize?&client_id=<CSPApplicationId>&response_type=code
对于中国,请使用以下链接:
GET https://login.chinacloudapi.cn/common/oauth2/authorize ?&client_id= <CSPApplicationId>&response_type=code&redirect_url= https://<CSPApplicationUrl_which_collects_refreshtoken>
或
GET https://login.chinacloudapi.cn/common/oauth2/authorize?&client_id= <CSPApplicationId>&response_type=code
授权代码调用跟踪: https://localhost:44395/?code=<authorization_code>&<rest of properties for state>
获取刷新令牌
然后,必须使用授权代码获取刷新令牌:
- 使用授权代码对 Azure AD 登录终结点
https://login.microsoftonline.com/CSPTenantID/oauth2/token进行 POST 调用。 有关示例,请参阅以下示例调用。 - 记下返回的刷新令牌。
- Microsoft Store Azure 密钥保管库中的刷新令牌。 有关详细信息,请参阅 Key Vault API 文档。
示例调用
POST 'https://login.microsoftonline.com/<partnerTenantId>/oauth2/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--form 'grant_type="authorization_code"' \
--form 'client_id=<application_id or client_id>' \
--form 'resource="https://graph.microsoft.com"' \
--form 'code="<authorization_code>"'
Response Body:
{
"token_type": "Bearer",
"scope": "DelegatedAdminRelationship.ReadWrite.All User.Read.All",
"expires_in": "4549",
"ext_expires_in": "4549",
"expires_on": "1652886571",
"not_before": "1652881721",
"resource": "https://graph.microsoft.com",
"access_token": "Access_token",
"refresh_token": "Refresh_token",
"id_token": "Id_token"
}
设置密钥保管库
首先,在云解决方案提供商合作伙伴的租户中创建新的 Web 应用程序。 如果 CPV 应用程序用于调用合作伙伴中心 API,CPV 应在 CPV 合作伙伴的租户中创建新的 Web 应用程序。
如果使用 Azure 密钥保管库:
- 使用适当的
<key-vault-name>方式创建 Azure 密钥保管库,并生成 DNS 名称,如下所示:https://<key-vault-name>.vault.azure.net - 将刷新令牌添加到密钥保管库。
提供对密钥保管库的访问权限
在密钥保管库的访问策略中,添加具有权限的 KeyVaultAccessApp 仅管理机密的获取和设置方面。
配置原型
原型有两个应用程序:
- 合作伙伴同意:表示一个 Web 应用程序,旨在接受来自云解决方案提供商合作伙伴的同意,并显示成功消息。
- 此应用程序将设置同意并捕获已同意用户的刷新令牌。
- 同意用户的刷新令牌用于为云解决方案提供商合作伙伴租户生成访问令牌。
- 云解决方案提供商应用程序或 CPV 应用程序:表示调用合作伙伴中心 API 和图形的主应用程序。
- 代表合作伙伴执行商务和用户操作的 API。
此应用程序在调用相应的 API 之前检索特定受众的访问令牌, (合作伙伴中心 API 或Graph) 。 它使用安全存储在密钥保管库中的刷新令牌。
合作伙伴同意应用程序 (云解决方案提供商)
云解决方案提供商 Web 配置
对于云解决方案提供商合作伙伴应用程序,该文件web.config包含以下部分。使用相应的应用程序 ID 和机密更新这些值。 对于主应用程序,请使用“certificate”作为 Web 应用程序机密而不是纯机密,因为它将提供额外的安全层。
<!-- AppID that represents CSP application -->
<add key="ida:CSPApplicationId" value="CSPApplicationIdValue" />
<!--
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="CSPApplicationSecretValue" />
<!-- AppID that is given access for keyvault to store the refresh tokens --> <add key="ida:KeyVaultClientId" value="KeyVaultClientIdValue" />
<!--
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="KeyVaultClientSecretValue" />
<!-- AAD instance: Global is .com, for different national clouds it changes German cloud: .de, China cloud: login.chinacloudapi.cn -->
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
云解决方案提供商应用程序配置
对于云解决方案提供商合作伙伴应用程序,该文件app.config包含以下部分。使用相应的应用程序 ID 和机密更新值。 对于主应用程序,请使用“certificate”作为 Web 应用程序机密而不是纯机密,因为它将提供额外的安全层。
<!-- AppID that represents CSP application -->
<add key="ida:CPVApplicationId" value="CPVApplicationIdValue" />
<!--
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="CPVApplicationSecretValue" />
<!-- AppID that is given access for keyvault to store the refresh tokens -->
<add key="ida:KeyVaultClientId" value="KeyVaultClientIdValue" />
<!--
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="KeyVaultClientSecretValue" />
<!-- AAD instance: Global is .com, for different national clouds it changes German cloud: .de,
China cloud: login.chinacloudapi.cn -->
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
合作伙伴同意应用程序 (CPV)
使用 CPV 应用程序的 CSP 可以调用 ApplicationConsent API,在客户租户上创建服务主体,以访问 Microsoft Graph来管理客户租户。 有关详细信息,请参阅 合作伙伴中心身份验证。
CPV Web 配置
对于云解决方案提供商合作伙伴应用程序,该文件web.config包含以下部分。使用相应的应用程序 ID 和机密更新这些值。 对于主应用程序,请使用“certificate”作为 Web 应用程序机密而不是纯机密,因为它将提供额外的安全层。
<!-- AppID that represents Control panel vendor application -->
<add key="ida:CPVApplicationId" value="CPVApplicationIdValue" />
<!--
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="CPVApplicationSecretValue" />
<!-- AppID that is given access for keyvault to store the refresh tokens -->
<add key="ida:KeyVaultClientId" value="KeyVaultClientIdValue" />
<!--
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="KeyVaultClientSecretValue" />
<!-- AAD instance: Global is .com, for different national clouds it changes German cloud: .de, China cloud: login.chinacloudapi.cn -->
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
CPV 应用程序配置
对于 CPV 合作伙伴应用程序,该文件 app.config 包含以下部分。使用相应的应用程序 ID 和机密更新值。 对于主应用程序,请使用“certificate”作为 Web 应用程序机密而不是纯机密,因为它将提供额外的安全层。
<!-- AppID that represents Control panel vendor application -->
<add key="ida:CPVApplicationId" value="CPVApplicationIdValue" />
<!--
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="CPVApplicationSecretValue" />
<!-- AppID that is given access for keyvault to store the refresh tokens -->
<add key="ida:KeyVaultClientId" value="KeyVaultClientIdValue" />
<!--
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="KeyVaultClientSecretValue" />
<!-- AAD instance: Global is .com, for different national clouds it changes German cloud: .de, China cloud: login.chinacloudapi.cn -->
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />





