gpt4 book ai didi

microsoft-graph-api - Microsoft Graph API BadRequest当前经过身份验证的上下文无效

转载 作者:行者123 更新时间:2023-12-04 07:15:26 25 4
gpt4 key购买 nike

我正在尝试开发一个简单的后台应用程序以连接到我的onedrive帐户(工作)并定期下载一些文件。

我遵循了本教程https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-client-creds

我已经在这里注册了应用程序https://apps.dev.microsoft.com/portal/register-app
我写下了client_idclient_secret
要获取访问 token ,我向发出POST请求

https://login.microsoftonline.com/common/oauth2/v2.0/token
具有以下形式的编码数据

{
'client_id': 'clientid here',
'client_secret': 'secret is here',
'scope': 'https://graph.microsoft.com/.default',
'grant_type': 'client_credentials',
}

我回来了 access_token
{'ext_expires_in': 0,
'token_type': 'Bearer',
'expires_in': 3600,
'access_token': 'eyJ0eXAiOiJKV1QiLCJhbGciO---SHORTENED FOR BREVITY'}

接下来,我向 https://graph.microsoft.com/v1.0/me发出一个GET请求(正确设置了 Bearer header )

并得到这个错误的响应(对于任何端点,我都会得到)
{
"error": {
"code": "BadRequest",
"message": "Current authenticated context is not valid for this request",
"innerError": {
"request-id": "91059f7d-c798-42a1-b3f7-2487f094486b",
"date": "2017-08-05T12:40:33"
}
}
}

我在应用程序设置中配置了这些权限
permissions

任何想法可能有什么问题吗?

最佳答案

我将提交一个错误来改进此可怕的错误消息。问题是您正在使用应用程序权限(client_credentials流)发出请求-没有登录的用户上下文。您的请求是/me,而/me本质上是已登录用户的别名-在这种情况下,没有别名!

您应该尝试调用https://graph.microsoft.com/v1.0/users但是,然后再执行此操作。在应用程序注册门户中,您选择了委派权限,但您正在使用应用程序权限进行调用。您应该删除委派的权限,然后选择适当的应用程序权限-要调用用户,请选择“User.Read.All”。然后,通过转到/adminconsent端点来确保同意/同意您的应用程序。

另请在此处阅读有关权限,委派权限和应用程序权限的更多信息:https://developer.microsoft.com/en-us/graph/docs/concepts/permissions_reference

希望这可以帮助,

关于microsoft-graph-api - Microsoft Graph API BadRequest当前经过身份验证的上下文无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45522223/

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