AcquireTokenAsync结果为null

时间:2018-02-21 16:26:53

标签: powershell azure-active-directory microsoft-graph

尝试获取azure广告应用的auth令牌和标头以提取图形api报告时,身份验证令牌结果返回null。我没有收到错误消息。已经工作了一个多星期了。有人有任何想法吗?

function Get-AuthToken {
    $TenantName = "foo.com"
    $ClientID = "blah-123-blah-123-blah"
    $RedirectURI = "urn:spoderman"

    Import-Module MSOnline

    $ModuleBase = (Get-Module MSOnline | Sort-Object Version -Descending | Select-Object -First 1).ModuleBase
    $Adal = "{0}\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" -f $ModuleBase
    $AdalForms = "$AdalForms = "{0}\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" -f $Modulebase"

    [System.Reflection.Assembly]::LoadFrom($Adal) | Out-Null
    [System.Reflection.Assembly]::LoadFrom($AdalForms) | Out-Null

    $Authority = "https://login.windows.net/$TenantName"
    $ClientCred = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential" -ArgumentList $ClientID, $ClientCred
    $AuthContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $Authority, $false

    $AuthResult = $AuthContext.AcquireTokenAsync($ResourceAppIdURI, $ClientCred).result

    return $AuthResult
}

$Token = Get-AuthToken

令牌返回null。

我已经使用ActiveDirectory.UserCredential$authContext.AcquireToken($ResourceAppIdURI, ClientID, $RedirectUri, "Always")来提升用户提示输入信用卡,但我希望将其作为自动化任务运行。希望我能够走上正确的轨道......

0 个答案:

没有答案