gpt4 book ai didi

azure - 我获取 token 的查询有问题吗?

转载 作者:行者123 更新时间:2023-12-03 01:38:13 24 4
gpt4 key购买 nike

我正在尝试使用 Powershell 从我的 Azure AD 获取 oauth token 。

我尝试将 token 生成到文本文件中,以查看请求第一步的结果。

我正在尝试获取 Azure 数字孪生 token 。您在 $resourceId 中看到的常量是 Microsoft 提供的用于请求 AzureDigitalTwins 的。这是我的脚本:

# Load ADAL methods
Add-Type -Path ".\MyPath\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"

$resultToken = ".\TokenTest.txt"

# Conf here
$aadInstance = "https://login.microsoftonline.com/"
$tenantId = "myTenantID"
$applicationId = "myAppID"
$applicationSecretKey = "myAppSecret"
$resourceId = "0b07f429-9f4b-4714-9392-cc5e8e80c8b0"


# Get an Access Token with ADAL
$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($aadInstance + $tenantId)
$clientCredential = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential($applicationId, $applicationSecretKey)
$authenticationResult = $authContext.AcquireTokenAsync($resourceId, $clientCredential)
($token = $authenticationResult.AccessToken) | Out-File $resultToken

运行脚本后,我的文本文件为空,但没有收到错误。

我在 C# 中使用完全相同的代码来获取 token ,它工作得很好,但显然在 Powershell 中不行。

这有问题吗?感谢您的回答。

最佳答案

找到答案了!只需将 .GetAwaiter().GetResult() 添加到 AcquireTokenAsync 方法即可!

$authenticationResult = $authContext.AcquireTokenAsync($resourceId, $clientCredential).GetAwaiter().GetResult()

关于azure - 我获取 token 的查询有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56259263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com