如何解决使用PowerShell无法获取https://management.azure.com/的刷新令牌
我正在尝试使用PowerShell获取“ https://management.azure.com/”资源的访问令牌和刷新令牌,但是我却获得了唯一的访问令牌。我也需要刷新令牌。我分享我的代码如下。
$clientID = '1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$secretKey = 'kdfudifkldfliKASDFKkdfjd-ddkjfidysikd'
$tenantID = 'fxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$password = ConvertTo-SecureString -String $secretKey -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($ClientID,$password)
Connect-AzureRmAccount -ServicePrincipal -Credential $credential -Tenant $tenantID
$authUrl = "https://login.windows.net/" + $tenantID + "/oauth2/token/"
$body = @{
"resource" = "https://management.azure.com/";
"grant_type" = "client_credentials";
"client_id" = $ClientID
"client_secret" = $secretKey
}
Write-Output "Getting Authentication-Token ..."
$adlsToken = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
Write-Output $adlsToken
------------输出-----------------
Getting Authentication-Token ...
token_type : Bearer
expires_in : 3599
ext_expires_in : 3599
expires_on : 1597999269
not_before : 1597995369
resource : https://management.azure.com/
access_token : J0uYFoioURT4CdISuUrRrr...
解决方法
该规范规定了 Client Credentials (客户端凭据)授予类型必须不允许发布刷新令牌。因此,答案是,您必须使用其他授权类型来接收带有访问令牌的刷新令牌。
因此,建议您使用auth code flow,它会在您请求令牌时返回刷新令牌。
更新:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。