New-PartnerAccessToken

Generate a new access token that can be used to access Partner Center.

Syntax

New-PartnerAccessToken
   -ApplicationId <String>
   [-Consent]
   [-Credential <PSCredential>]
   [-Environment <EnvironmentName>]
   [-RefreshToken <String>]
   -Resource <String>
   [-TenantId <String>]
   [<CommonParameters>]
New-PartnerAccessToken
   [-Consent]
   -Credential <PSCredential>
   [-Environment <EnvironmentName>]
   [-RefreshToken <String>]
   -Resource <String>
   [-ServicePrincipal]
   [-TenantId <String>]
   [<CommonParameters>]

Description

The New-PartnerAccessToken command generates a new access token that can be used to access Partner Center.

Examples

Example 1

PS C:\> $appId = '<AAD-AppId>'
PS C:\> $appSecret = '<AAD-AppSecret>' | ConvertTo-SecureString -AsPlainText -Force
PS C:\> $credential = New-Object System.Management.Automation.PSCredential $appId, $appSecret
PS C:\> New-PartnerAccessToken -Credential $credential -Resource https://api.partnercenter.microsoft.com -ServicePrincipal -TenantId '<TenantId>'

Generates a new access token using a service principal for authentication.

Example 2

PS C:\> $credential = Get-Credential
PS C:\> New-PartnerAccessToken -ApplicationId '<AAD-AppId>' -Credential $credential -Resource https://api.partnercenter.microsoft.com -TenantId '<TenantId>'

Generates a new access token using user credentials for authentication.

Example 3

PS C:\> $appId = '<AAD-AppId>'
PS C:\> $appSecret = '<AAD-AppSecret>' | ConvertTo-SecureString -AsPlainText -Force
PS C:\> $credential = New-Object System.Management.Automation.PSCredential $appId, $appSecret
PS C:\> $token = New-PartnerAccessToken -Consent -Credential $credential -Resource https://api.partnercenter.microsoft.com -ServicePrincipal

Performs the secure app model partner consent process. The $token.RefreshToken value should be stored in a secure location such as Azure Key vault. The Azure AD application used in this example much have urn:ietf:wg:oauth:2.0:oob configured as one of the reply URLs.

Example 4

PS C:\> $appId = '<AAD-AppId>'
PS C:\> $appSecret = '<AAD-AppSecret>' | ConvertTo-SecureString -AsPlainText -Force
PS C:\> $credential = New-Object System.Management.Automation.PSCredential $appId, $appSecret
PS C:\> New-PartnerAccessToken -RefreshToken '<Refresh-Token-Value>' -Resource https://api.partnercenter.microsoft.com -Credential $credential -ServicePrincipal

Generates a new access token using the refresh token. The Azure AD application used in this example much have urn:ietf:wg:oauth:2.0:oob configured as one of the reply URLs.

Required Parameters

-ApplicationId

The application identifier used to access Partner Center.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Credential

Credentials that represents the service principal.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Resource

The identifier of the target resource that is the recipient of the requested token.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ServicePrincipal

A flag indicating that a service principal will be used to authenticate.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-Consent

A flag that indicates that the intention is to perform the partner consent process.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Credential

Credentials that represents the service principal.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Environment

Name of the environment to be used during authentication.

Type:EnvironmentName
Aliases:EnvironmentName
Accepted values:GlobalCloud, ChinaCloud, GermanCloud, USGovernment
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-RefreshToken

The refresh token to use in the refresh flow.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-TenantId

The Azure AD domain or tenant identifier.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

Outputs

Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult