gpt4 book ai didi

azure - 微软图返回 "access token is empty"

转载 作者:行者123 更新时间:2023-12-03 15:49:40 24 4
gpt4 key购买 nike

我发布此请求:

 
POST https://login.microsoftonline.com:443/{my-tennant-here}/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id={client id here}
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&client_secret={client secret here}
&grant_type=client_credentials

这将返回:

 
{
"token_type": "Bearer",
"expires_in": 3599,
"ext_expires_in": 0,
"access_token": "eyJ0eX......
}

我已经使用 jwt.io 解码了 token ,它绝对不是空的。它包含 14 项权利要求。 aud、iss、tid 等...

然后我在此请求中使用访问 token

 
GET https://graph.microsoft.com/v1.0/users
Athorization: Bearer eyJ0eX...

然后我收到 401 Unauthorized with this body:

 
{
"error": {
"code": "InvalidAuthenticationToken",
"message": "Access token is empty.",
"innerError": {
"request-id": "",
"date": "2018-08-14T15:41:44"
}
}
}

预期结果是 200 Ok,主体包含用户列表

这是否仅仅意味着我的应用程序未经授权,并且错误消息只是误导性的(访问 token 为空)?还是我做错了什么?

更新:我注意到,虽然 token 确实包含声明,但它没有范围声明,这对我来说似乎有点奇怪。我假设它具有 User.Read.All 范围。应用程序(客户端 ID/客户端密码)应具有此权限。我收到的 token 中的声明具有以下声明:

 
aud: "<a href="https://graph.microsoft.com" rel="noreferrer noopener nofollow">https://graph.microsoft.com</a>",
iss: "<a href="https://sts.windows.net/my" rel="noreferrer noopener nofollow">https://sts.windows.net/my</a> tennant id",
iat: timestamp
nbf: timestamp
exp: timestamp
aio: looks like some kind of signature
app_displayname: "the expected app name"
appid: "the expected appid"
appidacr: "1"
idp: "<a href="https://sts.windows.net/" rel="noreferrer noopener nofollow">https://sts.windows.net/</a>...."
oid: "GUID"
sub: "GUID"
tid: "my tennant id"
uti: "value"
ver: 1.0

最佳答案

授权 header 拼写错误。

因此“访问 token 为空”实际上可能意味着不存在甚至“请求中没有授权 header ”。

关于azure - 微软图返回 "access token is empty",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51845317/

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