gpt4 book ai didi

azure - 为什么获取用户访问 token 会抛出 invalid_grant 错误?

转载 作者:行者123 更新时间:2023-12-02 06:27:46 24 4
gpt4 key购买 nike

我正在使用Microsoft Graph Postman Collections从 Postman 中测试常见的 Microsoft Graph API。但是,我在尝试获取用户访问 token

时陷入困境

下面是请求

POST /7c69806f-5754-488f-9dd8-7daa8afea4fd/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
SdkVersion: postman-graph/v1.0
cache-control: no-cache
Postman-Token: ac512133-5afe-47a3-ae9b-3b6c0b510ebd
grant_type=passwordclient_id=ebbe4872-5b7187-de6d6ddf7301client_secret=g99p8DWoxdUPY-%3F%40%5Bv7kt2g4BMxGscope=https%3A%2F%2Fgraph.microsoft.com%2F.defaultuserName=rohitdhamijagmail.onmicrosoft.compassword=Zcost%4080

在尝试“获取用户访问 token ”POST API 时,出现以下错误:

{
"error": "invalid_grant",
"error_description": "AADSTS50034: The user account rohitdhamijagmail.onmicrosoft.com does not exist in the 7c69806f-5754-488f-9dd8-7daa8afea4fd directory. To sign into this application, the account must be added to the directory.\r\nTrace ID: c0e97dd8-053d-4c99-81e4-354d7ae7d500\r\nCorrelation ID: 7e67450e-3054-48bc-b808-2f6277093dac\r\nTimestamp: 2020-03-03 09:38:09Z",
"error_codes": [
50034
],
"timestamp": "2020-03-03 09:38:09Z",
"trace_id": "c0e97dd8-053d-4c99-81e4-354d7ae7d500",
"correlation_id": "7e67450e-3054-48bc-b808-2f6277093dac",
"error_uri": "https://login.microsoftonline.com/error?code=50034"
}

用户帐户确实显示在我的 Azure 租户下,下面是所附的图像 enter image description here

可能是什么问题?注意:我已经正确配置了全局环境,因为我可以使用其他 API,例如获取用户信息等。

最佳答案

您的请求应该是这样的。

https://login.microsoftonline.com/YourTenant.onmicrosoft.com/oauth2/v2.0/token

client_id:b603c7be_Client_id_e61f925
scope:https://graph.microsoft.com/.default
client_secret:NpmwO/KDJ_client_secret:NpmwO_W0kWf1SbnL
username:tenentUser.onmicrosoft.com
password:YourUserPassword
grant_type:password

查看屏幕截图:

enter image description here

我按预期获得了 token

步骤:1

enter image description here

步骤:2

enter image description here

步骤:3

enter image description here

注意:

  1. Make sure your user belong to azure portal on your tenant
  2. Your Client Id belongs to that tenant
  3. Application secret is valid or not expired.

更新:如何获取租户 ID

enter image description here

更多信息您可以引用Official document

希望这会有所帮助。

关于azure - 为什么获取用户访问 token 会抛出 invalid_grant 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60504256/

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