gpt4 book ai didi

azure - PAT 生命周期管理 API 返回 203 非权威信息

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

我正在尝试通过 PAT 生命周期管理 API 创建 Azure DevOps 个人访问 token 以利用工作项 API,但收到 203 非权威信息错误:

Error Screenshot

这是 curl 请求:

curl --location ‘https://vssps.dev.azure.com/mayankaggarwal9919/\_apis/tokens/pats?api-version=7.1-preview.1%E2%80%99 –header ‘Content-Type: application/json’ –header ‘Authorization: Basic \\\[Redacted\\\]’ –header ‘Cookie: VstsSession=%7B%22PersistentSessionId%22%3A%229e3cefcb-0bf3-42cb-b3e3-9c76748cb94d%22%2C%22PendingAuthenticationSessionId%22%3A%2200000000-0000-0000-0000-000000000000%22%2C%22CurrentAuthenticationSessionId%22%3A%2200000000-0000-0000-0000-000000000000%22%2C%22SignInState%22%3A%7B%7D%7D; X-VSS-UseRequestRouting=True’ –data ’ { “displayName”: “new_token”, “scope”: “app_token”, “validTo”: “2023-12-01T23:46:23.319Z”, “allOrgs”: true } ’

通过在 Azure Active Directory 中注册应用程序并在 Postman 中点击下面提到的curl 请求,我能够生成不记名 token (需要在 PAT API 中传递) -

curl --location ‘https://login.microsoftonline.com/%7Btenantid%7D/oauth2/token%E2%80%99 –header ‘Content-Type: application/x-www-form-urlencoded’ –header ‘Cookie: fpc=Anwji51Th8BHmcdGaAhuKwcrrAAsAQAAAAbCo9wOAAAA; stsservicecookie=estsfd; x-ms-gateway-slice=estsfd’ –data-urlencode ‘grant_type=client_credentials’ –data-urlencode ‘client_id={clientid}’ –data-urlencode ‘client_secret={clientsecret}’ –data-urlencode ‘resource=https://management.azure.com/%E2%80%99

我尝试以 API Key、Basic 和 Bearer 等不同格式将 token 传递给 PAT Lifecycle API(上面共享的第一个curl 请求),只是为了点击并尝试,但所有这些都出现了相同的错误。以下是我授予创建的应用程序的 API 权限:

App Permissions

应用程序的 API 权限 这是我的应用程序的身份验证设置的样子 -

应用程序身份验证设置我还尝试通过在 Azure 本地 CLI - az account get-access-token 上运行此命令来生成需要传递到 PAT API 的不记名 token ,但在传递生成的 token 时我仍然收到相同的错误在 PAT 生命周期 API 中。

Authentication Settings

我可以从浏览器访问此 URL -https://dev.azure.com/mayankaggarwal9919,并且我还确保传递的不记名 token 中没有换行符。在我看来,发生这种情况是因为缺乏一些我无法弄清楚的权限。

任何见解都将受到高度赞赏。

我尝试了以下方法,但没有解决问题:

  • 提供对我创建的 Active Directory 应用程序的 Azure DevOps 资源访问权限。

  • 使用 Azure CLI 而不是 Postman 生成承载 token (需要传递到 PAT API)。

  • 验证了注册应用程序上与 Azure DevOps 相关的所有权限。

  • 通过 AAD 应用程序使用授权代码和范围 499b84ac-1321-427f-aa17-267ca6975798/.default 生成承载 token

  • 检查 token 中是否存在换行符。`

最佳答案

错误代码203表示小熊 token 不正确。

您的屏幕截图中的应用程序权限很好,因为它在我这边工作。

您可以使用以下授权请求来获取code值:

https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/authorize
?client_id=<appID>
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope= 499b84ac-1321-427f-aa17-267ca6975798/.default
&state=12345

您将得到如下代码:

enter image description here

如果您遇到类似AADSTS500113:没有为应用程序注册回复地址。的错误,请转到应用程序中的“身份验证”选项卡并添加 https://jwt.ms像这样重定向 URI 并保存。 enter image description here

然后,您可以使用授权代码流程生成访问 token ,方法是将范围更改为 499b84ac-1321-427f-aa17-267ca6975798/.default,并使用以下参数:

POST https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token
grant_type:authorization_code
client_id: <appID>
client_secret: <secret>
scope:499b84ac-1321-427f-aa17-267ca6975798/.default
code: <paste_code_from_above_request>
redirect_uri: https://jwt.ms

enter image description here

使用此访问 token ,我可以在 DevOps Rest api 中生成 PAT,请注意,您可以使用版本 7.0-preview.17.1-preview.1,但是不是 7.0

POST https://vssps.dev.azure.com/{organization}/_apis/tokens/pats?api-version=7.1-preview.1

enter image description here

您可以查看类似link供您引用。

关于azure - PAT 生命周期管理 API 返回 203 非权威信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77215793/

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