oauth-2.0 - Microsoft Graph API 的访问 token 立即过期

标签 oauth-2.0 azure-active-directory microsoft-graph-api

我正在关注this guide对 Microsoft Graph API 进行身份验证,并使用 Postman,我可以 POST/token 端点,成功获取 token :

post to get token

现在,复制该 token 并将其粘贴到 Authorization: Bearer {{token}} 中,我尝试向 https://graph.windows.net/my- 发出请求tenant/me?api-version=1.6/,但我得到的回复是

{
    "odata.error": {
        "code": "Authentication_ExpiredToken",
        "message": {
            "lang": "en",
            "value": "Your access token has expired. Please renew it before submitting the request."
        },
        "date": "2018-05-23T08:05:10",
        "requestId": "f56bcd26-4314-41c6-81b6-e6540aa7b0ae",
        "values": null
    }
}

我刚刚创建的 token 怎么会过期?

最佳答案

我怀疑 token 是否已过期,该消息似乎已关闭。

您正在尝试使用 MS Graph API 的 token 调用 Azure AD Graph API。 将范围更改为 https://graph.windows.net/.default,或调用 https://graph.microsoft.com/v1.0/me

此外,在使用客户端凭据流后,您无法调用 /me 端点。没有登录用户。您必须使用 /users/object-id-or-upn

关于oauth-2.0 - Microsoft Graph API 的访问 token 立即过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50483154/

相关文章:

microsoft-graph-api - Microsoft 应用程序注册中的重定向 URL

c# - OAuth 2.0 与 REST WCF 服务应用程序集成

http - 为什么 google oauth2 playground 无法返回数据?

azure - 从浏览器应用程序联系我的 ASP.NET Core 3.1 API 时,无法在访问 token 中看到角色声明

azure - 有没有办法在 azure Active Directory 中为 Web 应用程序用户添加自定义权限

c# - 如何使用用户 ID(对象 ID)从 Azure Active Directory 获取用户名

python - Outlook 365 api 中的身份验证

php - Google OAuth - 私有(private) IP 需要 device_id 和 device_name

azure - 使用 Azure Active Directory 保护 REST WebApi2 服务

botframework - 在 MS Teams 中检测 session 结束