gpt4 book ai didi

azure - 使用 Powershell 而不是 Bash 请求 Azure Databricks 访问 token

转载 作者:行者123 更新时间:2023-12-03 06:23:26 25 4
gpt4 key购买 nike

我在 Bash 中运行以下代码,并成功从 AAD 接收 Azure Databricks 访问 token 。

curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' \
https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token \
-d 'client_id=<app_id>' \
-d 'grant_type=client_credentials' \
-d 'scope=2ff814a6-3304-4ab8-85cb-cd0e6f879c1d%2F.default' \
-d 'client_secret=<app_secret>'

我正在尝试将其适应 PowerShell,这与我的用例更相关。我的等效 PowerShell 脚本是:

$headers = @{'Content-Type'='application/x-www-form-urlencoded'}
$method = 'POST'
$url = 'https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token'
$body = @{'client_id'='<app_id>'; 'grant_type'='client_credentials'; 'scope'='2ff814a6-3304-4ab8-85cb-cd0e6f879c1d%2F.default'; 'client_secret'='<app_secret>'}

Invoke-WebRequest $url -Method $method -Headers $headers -Body $body

当我仅运行 PowerShell 脚本时,我收到一条错误,指出“为范围 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d%2F.default 提供的值无效。客户端凭据流必须具有带/的范围值。默认后缀为资源标识符”。我发送到 api 的 url 编码范围显然带有“.default”后缀,所以我不确定问题是什么...知道什么可能导致此错误吗?

最佳答案

我尝试在我的环境中重现并得到如下相同的错误:

enter image description here

要解决该错误,请确保将范围作为 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default 传递,如下所示:

$headers = @{'Content-Type'='application/x-www-form-urlencoded'}
$method = 'POST'
$url = 'https://login.microsoftonline.com/1810a95e-99f3-46e0-84e8-8axxxx30/oauth2/v2.0/token'
$body = @{'client_id'='52254c1f-d4a1-454d-bc37-d66xxxxe'; 'grant_type'='client_credentials'; 'scope'='2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default'; 'client_secret'='jFv8Q~QscXf~7ANRVrv9qLx118CJlrowvxxxx'}

Invoke-WebRequest $url -Method $method -Headers $headers -Body $body

访问 token 已成功生成,如下所示:

enter image description here

关于azure - 使用 Powershell 而不是 Bash 请求 Azure Databricks 访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75730631/

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