OAuth 与 O365 的集成失败,错误为 AADSTS65005

2023-07-16php开发问题
3

本文介绍了OAuth 与 O365 的集成失败,错误为 AADSTS65005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我们有一个网站(建立在 php 框架上),我们为教师/学生提供在线教育工具.我们已经与 google.com 进行了 OAuth 集成,用户可以使用他们的 google 帐户(可以是个人 gmail 帐户或谷歌应用程序域的成员)注册"和登录"到我们的网站.

We have a web site (built on a php framework) where we provide online educational tools for teachers/students. We have done an OAuth integration with google.com where users can 'sign up' and 'sign in' to our site using their google accounts (could be a personal gmail account, or a member of a google apps domain).

我们正在尝试与 O365 进行类似的集成,我们的网站可以向 O365 询问用户的电子邮件和名字/姓氏,以便我们可以在我们的网站上为他们创建一个帐户,创建帐户后,让他们登录.我们在 Azure -> Active Directory 中创建了一个应用程序列表,并生成了客户端 ID 和密码,并将它们插入到 PHP 代码中.OAuth 工作流程此处描述一直有效,直到我尝试并使用 POST 请求向 https://login.windows.net/common/oauth2 请求访问令牌/令牌.它重定向回我的 redirect_uri 但它没有给我授权码,而是在 URL 中给我这些参数:

We are trying to do a similar integration with O365 where our website can ask O365 for user's email and first/last names so we can create an account for them on our site, and once the account is created, log them in. We have created an Application listing in Azure -> Active Directory, and have generated the client ID and secret, and plugged them into out PHP code. The OAuth workflow described here works up until the point where I try and request the access token using a POST request to https://login.windows.net/common/oauth2/token. It redirects back to my redirect_uri but instead of giving me the auth code, it gives me these params in the URL:

[error] => access_denied
[error_description] => AADSTS65005: The client application has requested access to resource 'https://outlook.office365.com/'. This request has failed because the client has not specified this resource in its requiredResourceAccess list.
Trace ID: xxxxxx
Correlation ID: xxxxxx
Timestamp: 2014-09-29 06:28:25Z
[state] => xxxxxx

我只需要 O365 给我用户的电子邮件和 f/l 名称.肯定有一个快速解决方案,我错过了吗?

All I need is for O365 to give me the user's email and f/l names. Surely there's a quick fix for this that I am missing?

推荐答案

默认情况下,已注册的应用程序配置为请求读取用户的个人资料",一旦用户同意,该应用程序就可以获取用户令牌(如果使用 OpenID Connect,则为 id 令牌)并在调用 Azure AD 图形 API.受 Azure AD 保护的应用程序当前必须预先配置它们所需的权限范围(作为应用程序注册体验的一部分,在其他应用程序的权限"部分下).在这里,您似乎已将 Outlook.com 指定为需要代码和访问令牌的资源,但您的应用未配置为允许访问 O365 Outlook.com/Exchange Online.

By default, a registered app is configured to request "Read the user's profile", which once consented to by the user, allows the app to get a user token (id token if using OpenID Connect) and read the signed in user's profile (including their mail address or addresses) when calling the Azure AD Graph API. Apps secured by Azure AD must currently configure the permission scopes they require up front (as part of the app registration experience, under the "Permissions to other applications" section). Here it looks like you've specified Outlook.com as the resource that you'd like a code and access token for, but your app is not configured to allow access to O365 Outlook.com/Exchange Online.

请尝试将请求中的资源设置为 Azure AD - https://graph.windows.net/.这应该适合你.然后,您可以交换访问令牌的代码以调用 Azure AD Graph API.

Please try setting the resource in your request to Azure AD - https://graph.windows.net/. That should work for you. You can then swap the code for an access token to call the Azure AD Graph API.

希望能帮到你

这篇关于OAuth 与 O365 的集成失败,错误为 AADSTS65005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17