API呼叫失败,令牌从PowerShell脚本到期
Invoke-restMethod:{“ error”:{“代码”:“ expiredAuthenticationToken”,message“”“访问令牌expiry utc时间早于UTC时间}
脚本运行超过一个小时(确切地运行它,可用于1.40 mins ), the above error happens 1 out of 2 scenarios.
方案:1个
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
$nextLink = "https://management.azure.com/subscriptions/$($subscriptionId)/providers/Microsoft.Consumption/usageDetails?`$expand=meterDetails&`$filter=properties%2FusageStart%20ge%20'$($firstOfMonth)'%20and%20properties%2FusageEnd%20le%20'$($lastOfMonth)'&api-version=2019-10-01"
方案:2
$token = (Get-AzAccessToken -ResourceUrl "https://management.azure.com" - TenantId "").Token
Invoke-RestMethod : {"error":{"code" : "ExpiredAuthenticationToken", message"" "The access token expiry UTC time is earlier than UTC time"}
$nextLink = "https://management.azure.com/subscriptions/$($subscriptionId)/providers/Microsoft.Consumption/usageDetails?`$expand=meterDetails&`$filter=properties%2FusageStart%20ge%20'$($firstOfMonth)'%20and%20properties%2FusageEnd%20le%20'$($lastOfMonth)'&api-version=2019-10-01"
Invoke-RestMethod : {"error":{"code" : "ExpiredAuthenticationToken", message"" "The access token expiry UTC time is earlier than UTC time"}
Script runs For more than an hour (to be precise it runs For 1.40 mins ), the above error happens 1 out of 2 scenarios.
Scenario: 1
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
$nextLink = "https://management.azure.com/subscriptions/$($subscriptionId)/providers/Microsoft.Consumption/usageDetails?`$expand=meterDetails&`$filter=properties%2FusageStart%20ge%20'$($firstOfMonth)'%20and%20properties%2FusageEnd%20le%20'$($lastOfMonth)'&api-version=2019-10-01"
Scenario: 2
$token = (Get-AzAccessToken -ResourceUrl "https://management.azure.com" - TenantId "").Token
Invoke-RestMethod : {"error":{"code" : "ExpiredAuthenticationToken", message"" "The access token expiry UTC time is earlier than UTC time"}
$nextLink = "https://management.azure.com/subscriptions/$($subscriptionId)/providers/Microsoft.Consumption/usageDetails?`$expand=meterDetails&`$filter=properties%2FusageStart%20ge%20'$($firstOfMonth)'%20and%20properties%2FusageEnd%20le%20'$($lastOfMonth)'&api-version=2019-10-01"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论