Applies to: Partner Center | Partner Center operated by 21Vianet | Partner Center for Microsoft Cloud for US Government
Partner Center uses Microsoft Entra ID for authentication. When interacting with the Partner Center API, SDK, or PowerShell module you must correctly configure a Microsoft Entra application and then request an access token. Access tokens obtained using app only or app + user authentication can be used with the Partner Center. However, there are two important items that need to be considered
Use multifactor authentication when accessing the Partner Center API using app + user authentication. For more information regarding this change, see Enable secure application model.
Not all of the operations the Partner Center API support app only authentication. There are certain scenarios where you'll be required to use app + user authentication. Under the Prerequisites heading on each article, you find documentation that states whether app only authentication, app + user authentication, or both are supported.
ข้อสำคัญ
Azure Active Directory (Azure AD) Graph is deprecated as of June 30, 2023. Going forward, we're making no further investments in Azure AD Graph. Azure AD Graph APIs have no SLA or maintenance commitment beyond security-related fixes. Investments in new features and functionalities will only be made in Microsoft Graph.
We'll retire Azure AD Graph in incremental steps so that you have sufficient time to migrate your applications to Microsoft Graph APIs. At a later date that we will announce, we will block the creation of any new applications using Azure AD Graph.
To begin, you need to make sure that you have both a primary Partner Center account, and an integration sandbox Partner Center account. For more information, see Set up Partner Center accounts for API access. Make note of the Microsoft Entra App registration ID and Secret (client secret is required for App only identification) for both your primary account and your integration sandbox account.
Sign in to Microsoft Entra ID from the Azure portal. In permissions to other applications, set permissions for Windows Azure Active Directory to Delegated Permissions, and select both Access the directory as the signed-in user and Sign in and read user profile.
In the Azure portal, Add application. Search for "Microsoft Partner Center," which is the Microsoft Partner Center application. Set the Delegated Permissions to Access Partner Center API. If you're using Partner Center for Microsoft Cloud for US Government, this step is mandatory. If you're using Partner Center global instance, this step is optional. CSP Partners can use the App Management feature in Partner Center to bypass this step for Partner Center global instance.
App-only authentication
If you would like to use app-only authentication to access the Partner Center REST API, .NET API, Java API, or PowerShell module then you can do so by using the following instructions.
The Secure Application Model is now used to provide secure, scalable, and future-proof authentication for Partner Center API access. This approach improves security by using modern authentication mechanisms such as app-only and app+user access tokens via Azure AD. For more information, see Enable secure application model.
Partner consent
The partner consent process is an interactive process where the partner authenticates using multifactor authentication, consents to the application, and a refresh token is stored in a secure repository such as Azure Key Vault. We recommend that a dedicated account for integration purposes be used for this process.
ข้อสำคัญ
The appropriate multifactor authentication solution should be enabled for the service account used in the partner consent process. If it isn't then the resulting refresh token will not be compliant with security requirements.
Samples for App + User authentication
The partner consent process can be performed in many ways. To help partners understand how to perform each required operation, we've developed the following samples. When you implement the appropriate solution in your environment, it's important that you develop a solution that is compliant with your coding standards and security policies.
.NET (app+user authentication)
The partner consent sample project demonstrates how to utilize a website developed using ASP.NET to capture consent, request a refresh token, and securely store it in Azure Key Vault. Perform the following steps to create the required prerequisites for this sample.
Create an instance of Azure Key Vault using the Azure portal or the following PowerShell commands. Before executing the command, be sure to modify the parameter values accordingly. The vault name must be unique.
Azure PowerShell
Login-AzureRmAccount# Create a new resource groupNew-AzureRmResourceGroup -Name ContosoResourceGroup -Location EastUS
New-AzureRmKeyVault -Name'Contoso-Vault' -ResourceGroupName'ContosoResourceGroup' -Location'East US'
Be sure to make note of the application identifier and secret values because they'll be used in the steps below.
Grant the newly create Microsoft Entra application the read secrets permissions using the Azure portal or the following commands.
PowerShell
# Connect to Microsoft GraphConnect-MgGraph -Scopes"User.Read"# Get the application$app = Get-MgApplication -Filter"appId eq 'ENTER-APP-ID-HERE'"# Set the Key Vault access policySet-AzKeyVaultAccessPolicy -VaultName ContosoVault -ObjectId$app.Id -PermissionsToSecrets get
Create a Microsoft Entra application that is configured for Partner Center. Perform the following actions to complete this step.
Open the PartnerConsent project found in the Partner-Center-DotNet-Samples\secure-app-model\keyvault directory.
Populate the application settings found in the web.config
XML
<!-- AppID that represents CSP application --><addkey="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.
--><addkey="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.
--><addkey="KeyVaultEndpoint"value="" /><!-- App ID that is given access for KeyVault to store refresh tokens --><addkey="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.
--><addkey="ida:KeyVaultClientSecret"value="" />
ข้อสำคัญ
Sensitive information such as application secrets should not be stored in configuration files. It was done here because this is a sample application. With your production application we strongly recommend that you use certificate-based authentication. For more information, see Certificate credentials for application authentication.
When you run this sample project, it prompts you for authentication. After successfully authenticating, an access token is requested from Microsoft Entra ID. The information returned from Microsoft Entra ID includes a refresh token that is stored in the configured instance of Azure Key Vault.
Java (app+user authentication)
The partner consent sample project demonstrates how to utilize a website developed using JSP to capture consent, request a refresh token, and secure store in Azure Key Vault. Perform the following to create the required prerequisites for this sample.
Create an instance of Azure Key Vault using the Azure portal or the following PowerShell commands. Before executing the command, be sure to modify the parameter values accordingly. The vault name must be unique.
Azure PowerShell
Login-AzureRmAccount# Create a new resource groupNew-AzureRmResourceGroup -Name ContosoResourceGroup -Location EastUS
New-AzureRmKeyVault -Name'Contoso-Vault' -ResourceGroupName'ContosoResourceGroup' -Location'East US'
Sensitive information such as application secrets should not be stored in configurations files. It was done here because this is a sample application. With your production application, we strongly recommend that you use certificate based authenticate. For more information, see Key Vault Certificate authentication.
When you run this sample project, it prompts you for authentication. After successfully authenticating, an access token is requested from Microsoft Entra ID. The information returned from Microsoft Entra ID includes a refresh token that is stored in the configured instance of Azure Key Vault.
Cloud Solution Provider authentication
Cloud Solution Provider partners can use the refresh token obtained through the partner consent process.
Samples for Cloud Solution Provider authentication
To help partners understand how to perform each required operation, we've developed the following samples. When you implement the appropriate solution in your environment, it's important that you develop a solution that is compliant with your coding standards and security policies.
Open the CSPApplication project found in the Partner-Center-DotNet-Samples\secure-app-model\keyvault directory.
Update the application settings found in the App.config file.
XML
<!-- AppID that represents CSP application --><addkey="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.
--><addkey="ida:CSPApplicationSecret"value="" /><!-- Endpoint address for the instance of Azure KeyVault --><addkey="KeyVaultEndpoint"value="" /><!-- AppID that is given access for keyvault to store the refresh tokens --><addkey="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.
--><addkey="ida:KeyVaultClientSecret"value="" />
Set the appropriate values for the PartnerId and CustomerId variables found in the Program.cs file.
C#
// 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>";
When you run this sample project, it obtains the refresh token obtained during the partner consent process. Then, it requests an access token to interact with the Partner Center SDK on the partner's behalf. Finally, it requests an access token to interact with Microsoft Graph on behalf of the specified customer.
When you run this sample project, it obtains the refresh token obtained during the partner consent process. Then, it requests an access token to interact with the Partner Center SDK on the partner's behalf.
Optional - uncomment the RunAzureTask and RunGraphTask function calls if you want to see how to interact with Azure Resource Manager and Microsoft Graph on behalf of the customer.
Control Panel Provider authentication
Control panel vendors need to have each partner they support perform the partner consent process. Once that is completed the refresh token obtained through that process is used to access the Partner Center REST API and .NET API.
หมายเหตุ
Control panel vendors should have at minimum the Cloud Application Administrator role in the customer's tenant.
Samples for Cloud Panel Provider authentication
To help control panel vendors understand how to perform each required operation, we've developed the following samples. When you implement the appropriate solution in your environment, it's important that you develop a solution that is compliant with your coding standards and security policies.
.NET (CPV authentication)
Develop and deploy a process for Cloud Solution Provider partners to provide the appropriate consent. For more information an example, see partner consent.
ข้อสำคัญ
User credentials from a Cloud Solution Provider partner should not be stored. The refresh token obtained through the partner consent process should be stored and used to request access tokens for interacting with any Microsoft API.
Open the CPVApplication project found in the Partner-Center-DotNet-Samples\secure-app-model\keyvault directory.
Update the application settings found in the App.config file.
XML
<!-- AppID that represents Control panel vendor application --><addkey="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.
--><addkey="ida:CPVApplicationSecret"value="" /><!-- Endpoint address for the instance of Azure KeyVault --><addkey="KeyVaultEndpoint"value="" /><!-- AppID that is given access for keyvault to store the refresh tokens --><addkey="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.
--><addkey="ida:KeyVaultClientSecret"value="" />
Set the appropriate values for the PartnerId and CustomerId variables found in the Program.cs file.
C#
// 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>";
When you run this sample project, it obtains the refresh token for the specified partner. Then, it requests an access token to access Partner Center and Microsoft Graph on behalf of the partner. The next task it performs is the deletion and creation of permission grants into the customer tenant. Since there's no relationship between the control panel vendor and the customer, these permissions need to be added using the Partner Center API. The following example shows how to accomplish that.
C#
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());
After these permissions have been established, the sample performs operations using Microsoft Graph on behalf of the customer.
Develop and deploy a process for Cloud Solution Provider partners to provide the appropriate consent. For more information and an example, see the partner consent.
ข้อสำคัญ
User credentials from a Cloud Solution Provider partner should not be stored. The refresh token obtained through the partner consent process should be stored and used to request access tokens for interacting with any Microsoft API.
When you run this sample project, it obtains the refresh token for the specified partner. Then, it requests an access token to access Partner Center on behalf of the partner. The next task it performs is the deletion and creation of permission grants into the customer tenant. Since there's no relationship between the control panel vendor and the customer, these permissions need to be added using the Partner Center API. The following example shows how to grant the permissions.
Java
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);
Uncomment the RunAzureTask and RunGraphTask function calls if you want to see how to interact with Azure Resource Manager and Microsoft Graph on behalf of the customer.