“Unexpected Error” connecting to Azure AD with Connect-MsolService -AccessToken

前端 未结 1 784
攒了一身酷
攒了一身酷 2021-01-16 08:10

I\'m using the new preview version of the Azure AD PS module. I\'m trying to connect via the new AccessToken parameter:

Connect-MsolService - AccessToken ey         


        
相关标签:
1条回答
  • 2021-01-16 09:06

    I was not able to replicate your issue. Let me tell you what I did to get it working:

    I first got an access token for a native client app targeting the Graph API:

    $clientId = "<GUID>";
    $tenantId = "<tenant>.onmicrosoft.com";
    $resourceId = "https://graph.windows.net"
    $redirectUri = new-object System.Uri("urn:ietf:wg:oauth:2.0:oob")
    $login = "https://login.microsoftonline.com"
    
    $authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext("{0}/{1}" -f $login,$tenantId);
    $authenticationResult = $authContext.AcquireToken($resourceId,$clientID,$redirectUri);
    $token = $authenticationResult.AccessToken
    

    Then I used that token in PowerShell:

    PS C:\Users\shtabriz> Connect-MsolService -AccessToken eyJ0eXAiOiJKV1QiLCJ...
    PS C:\Users\shtabriz> Get-MsolUser
    
    UserPrincipalName                                     DisplayName       isLicensed
    -----------------                                     -----------       ----------
    test@shawntest.onmicrosoft.com                        TestMe            False
    shtabriz_microsoft.com#EXT#@shawntest.onmicrosoft.com Shawn Tabrizi     False
    admin@shawntest.onmicrosoft.com                       ShawnTabriziAdmin False
    Alex@shawntest.onmicrosoft.com                        Alex Wu           False
    language@shawntest.onmicrosoft.com                    Language          False
    languageportal@shawntest.onmicrosoft.com              Language Portal   False
    

    What kind of access token are you getting? Would you mind sharing it? Or at least a JWT decompiled version of it without a signature?

    If you want to take this elsewhere, feel free to reach out to us at

    AADPowerShellPreview@microsoft.com

    Please include the log files found here:

    C:\Users[youralias]\AppData\Local\Microsoft\Office365\Powershell

    0 讨论(0)
提交回复
热议问题