Azure身份验证令牌异常关闭的连接

时间:2019-02-22 17:02:38

标签: rest azure powershell http

在尝试获取身份验证令牌以连接到Azure时出现异常。我需要使用REST来获取一些Active Directory数据。

例外是:

  

System.Net.Http.HttpRequestException:无法从   传输连接:现有连接被强制关闭   远程主机

代码如下:

$authorityURL = "https://login.windows.net/common/oauth2/authorize/" 
$resourceURL = "https://analysis.windows.net/powerbi/api"

$clientID = 'al;ksdfj02340jaslsdf'
$userName = 'erik'
$password = 'mypass'

$credential = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserPasswordCredential($userName, $password);
$authenticationContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($authorityURL);

# This object is throwing an exception...
# System.Net.Http.HttpRequestException
# Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host
authenticationResult = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions]::AcquireTokenAsync($authenticationContext, $resourceURL, $clientID, $credential)

谢谢! 埃里克·W。

0 个答案:

没有答案