且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Azure AD OAuth2 访问令牌请求错误 - 400 错误请求

更新时间:2022-01-13 08:13:44

我使用了 fiddler 调试请求,我找到了完整的错误消息:用户或管理员未同意使用该应用程序.我在谷歌上搜索了这条消息,发现了一些堆栈文章和 github 问题线程,它们引导我找到解决方案:我的请求一直在基本 URL 中使用common"作为租户 ID,而实际上我需要使用我的 Azure 租户我通过这个 answer on stack 获得的 ID.我的身份验证请求的新基本 URL 现在看起来像:

I used fiddler to debug the request and I found the full error message: The user or administrator has not consented to use the application. I googled this message for a bit and found some stack articles and github issue threads that lead me to the solution: my request had been using "common", in the base URL, as the tenant ID when actually I needed to use my Azure tenant ID which I acquired through this answer on stack. My new base URL for the authentication requests now looks like:

https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/authorize 

其中xxxx-....xxx"将替换为您的 Azure 租户 ID!

where "xxxx-....xxx" would be replaced by your Azure tenant id!