Partner Center multi-factor authentication using PowerShell (2024)

  • Article

Multi-Factor Authentication (MFA) helps safeguard access to data and applications while maintaining simplicity for users. It provides additional security by requiring a second form of authentication and delivers strong authentication through a range of easy to use authentication methods. Users may or may not be challenged for Multi-Factor Authentication based on configuration decisions that an administrator makes. Starting on August 1, 2019 all partners involved with the Cloud Solution Provider are contractually required to have Multi-Factor Authentication enforced for all accounts in their partner tenant. See the partner security requirements for more information.

Secure Application Model

The requirement for Multi-Factor Authentication can complicate any automation that you have developed because a second form of authentication must be provided when authenticating. To content with this requirement, the Secure Application Model was developed to provide guidance on how the appropriate authentication can be performed in non-interactive scenarios. This model is comprised of two distinct steps

StepDescription
ConsentThis where you will authenticate interactively using the authorization code flow or device code flow. The response from Azure Active Directory will contain an access token and a refresh token. The refresh token value should be stored somewhere secure, such as Azure Key Vault. This value will be used by your application, or script, instead of user credential when authenticating.
ExchangeUsing the securely stored refresh token, generated through the consent step, you will request a new access token from Azure Active Directory. See refresh the access token for more information regarding the refresh token value.

Important

By default, the lifetime of a refresh token is 90 days. So, it is important that you have a process for updating the refresh token prior to the expiration. If it does expire, you will receive an error similar to the following when attempting to exchange it for an access token The refresh token has expired due to inactivity. The token was issued on 2019-01-02T09:19:53.5422744Z and was inactive for 90.00:00:00.

Consent

The consent step can be performed through several different methods. When using PowerShell it is recommended to use the New-PartnerAccessToken cmdlet. The following is an example of how you can request a new access token for use with the Partner Center API, SDK, or PowerShell module.

$credential = Get-CredentialNew-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Scopes 'https://api.partnercenter.microsoft.com/user_impersonation' -ServicePrincipal -Credential $credential -Tenant 'yyyy-yyyy-yyyy-yyyy' -UseAuthorizationCode

Important

When using the UseAuthorizationCode parameter you will be prompted to authentication interactively using the authorization code flow. The redirect URI value will generated dynamically. This generation process will attempt to find a port between 8400 and 8999 that is not in use. Once an available port has been found, the redirect URL value will be constructed (e.g. http://localhost:8400). So, it is important that you have configured the redirect URI value for your Azure Active Directory application accordingly.

The first command gets the service principal credentials (application identifier and secret), and then stores them in the $credential variable. The second command will generate a new access token using the service principal credentials stored in the $credential variable and the authorization code flow. The output from this command will contain several values, including a refresh token. That value should be stored somewhere secure such as Azure Key Vault because it will be used instead of user credentials in future operations.

Exchange

The exchange step can be performed through a number of different methods. When using PowerShell it is recommended to use the New-PartnerAccessToken cmdlet. The following is an example of how to exchange a refresh token for an access token that can be used with the Partner Center API, SDK, or PowerShell module.

$credential = Get-Credential$refreshToken = '<refreshToken>'New-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken -Scopes 'https://api.partnercenter.microsoft.com/user_impersonation' -ServicePrincipal -Tenant 'yyyy-yyyy-yyyy-yyyy'

The first command gets the service principal credentials (application identifier and secret), and then stores them in the $credential variable. The third command will generate a new access token using the service principal credentials stored in the $credential variable and the refresh token stored in the $refreshToken variable for authentication.

Samples

The following sections demonstrate how to use the New-PartnerAccessToken cmdlet to request access tokens and connect to other commonly used PowerShell modules.

Azure

Azure PowerShell

$credential = Get-Credential$refreshToken = '<RefreshToken>'$azureToken = New-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken -Scopes 'https://management.azure.com//user_impersonation' -ServicePrincipal -Tenant 'yyyy-yyyy-yyyy-yyyy'$graphToken = New-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken -Scopes 'https://graph.windows.net/.default' -ServicePrincipal -Tenant 'yyyy-yyyy-yyyy-yyyy'# Az ModuleConnect-AzAccount -AccessToken $token.AccessToken -AccountId 'azureuser@contoso.com' -GraphAccessToken $graphToken.AccessToken -TenantId 'xxxx-xxxx-xxxx-xxxx'

Note

When connecting to an environment where you have admin on behalf of privileges, you will need to specify the tenant identifier for the target environment through the Tenant parameter. With respect to the Cloud Solution Provider program this means you will specify the tenant identifier of the customer's Azure Active Directory tenant using the Tenant parameter.

Microsoft 365

Azure Active Directory

$credential = Get-Credential$refreshToken = '<RefreshToken>'$aadGraphToken = New-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken -Scopes 'https://graph.windows.net/.default' -ServicePrincipal -Tenant 'yyyy-yyyy-yyyy-yyyy'$graphToken = New-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken -Scopes 'https://graph.microsoft.com/.default' -ServicePrincipal -Tenant 'yyyy-yyyy-yyyy-yyyy'Connect-AzureAD -AadAccessToken $aadGraphToken.AccessToken -AccountId 'azureuser@contoso.com' -MsAccessToken $graphToken.AccessToken

Note

When connecting to an environment where you have admin on behalf of privileges, you will need to specify the tenant identifier for the target environment through the Tenant parameter. With respect to the Cloud Solution Provider program this means you will specify the tenant identifier of the customer's Azure Active Directory tenant using the Tenant parameter.

Exchange Online PowerShell

For more information about this scenario, see Use Exchange Online PowerShell v3 with GDAP and App consent.

MS Online

$credential = Get-Credential$refreshToken = '<RefreshToken>'$aadGraphToken = New-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken -Scopes 'https://graph.windows.net/.default' -ServicePrincipal -Tenant 'yyyy-yyyy-yyyy-yyyy'$graphToken = New-PartnerAccessToken -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken -Scopes 'https://graph.microsoft.com/.default' -ServicePrincipal -Tenant 'yyyy-yyyy-yyyy-yyyy'Connect-MsolService -AdGraphAccessToken $aadGraphToken.AccessToken -MsGraphAccessToken $graphToken.AccessToken

Partner Center

$credential = Get-Credential$refreshToken = '<refreshToken>'Connect-PartnerCenter -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken

The first command gets the service principal credentials (application identifier and secret), and then stores them in the $credential variable. This is required if the refresh token was generate using a web application because Azure Active Directory requires the application identifier and secret be included with the request.

Partner Center multi-factor authentication using PowerShell (2024)
Top Articles
Highway 420 East Bremerton
Rachel Griffin Bikini
Craigslist Free Stuff Merced Ca
Bolongaro Trevor Backpack
Is Jennifer Coffindaffer Married
Levidia 2019
Papa's Pizzeria - Play Online at Coolmath Games
Mensenlinq: Overlijdensberichten zoeken in 2024
Craigslist Cars And Trucks For Sale Private Owners
Craigslist Rooms For Rent North County San Diego
Hillsborough County Florida Recorder Of Deeds
Peanut Oil Can Be Part Of A Healthy Diet — But Only If It's Used This Way
Parents & Students · Infinite Campus
Irissangel
Sofia the baddie dog
Netflix Phone Number: Live Human Help - Netflix - Claimyr
Litter Robot 3 Dump Position Fault
Kaelis Dahlias
The Guardian Crossword Answers - solve the daily Crossword
Party City Enfield Photos
Baca's Funeral Chapels & Sunset Crematory Las Cruces Obituaries
Mighty B Wcostream
636-730-9503
Crowder Hite Crews Funeral Home Obituaries
Weather | Livingston Daily Voice
Vidant My Chart Login
Freeman Funeral Home Chapmanville Wv Obits
Bfri Forum
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
Milwaukee Nickname Crossword Clue
Nike Factory Store - Howell Photos
Uhauldealer.com Login Page
Owyhee County Extension Office
Lolalytics Aram
Hatcher Funeral Home Aiken Sc
Gwcc Salvage
619-354-3954
Look Who Got Busted New Braunfels
Google Flights Missoula
How to Choose Where to Stay When You Visit Pittsburgh
Chalupp's Pizza Taos Menu
Stony Brook Citrix Login
Melissa Black County Court Judge Group 14
Space Coast Fl Craigslist
Meg 2: The Trench Showtimes Near Phoenix Theatres Laurel Park
Gtl Visit Me Alameda
Photogeek Goddess
Watch Stephen Miller Have A Full Meltdown When Asked To Back Up Crime Claim With Facts
This Meteorologist Was Wardrobe Shamed, So She Fought Back | Star 101.3 | Marcus & Corey
1636 Fire Red Squirrels
Discord Id Grabber
Edible Arrangements Track
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 6364

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.