我希望有人可以帮忙解决这个问题,我完全陷入困境.
预先信息
我有一个工作的coldfusion应用程序(基于web),实现了完整的Google Oauth2验证过程.这很好,我可以检索电子邮件发布命令.现在我想对微软的Outlook做同样的事情
问题
当我尝试对令牌URL执行HTTP POST请求时,我得到一个响应,我的重定向URI无效,因为它与我用来获取代码的那个不一样.
什么有效
我可以通过对oauth端点执行GET请求来检索代码.我在azure门户中添加了一个重定向URI(多个uri)当我调用这个URL时,我从outlook获得一个登录屏幕,之后我成功地重定向回我的应用程序.所以我猜重定向URI是正确的,它一切正常.
当我尝试使用收到的代码获取令牌时,我得到重定向错误.我完全不知道这些URI是不是一样的事实.我已经三重检查了一切,但找不到任何错误.
错误
这是我得到的错误:
“error”:“invalid_grant”,“error_description”:“AADSTS70000:’redirect_uri’提供的值无效.该值必须与用于获取授权码的重定向URI完全匹配.
我尝试过不同种类的格式.破折号结束或没有破折号.但事实仍然是重定向URL适用于前面的步骤.那为什么不用这个呢?
当我玩它时,我也会得到像“Code expired”这样的消息,所以我知道它正常工作.我在天蓝色的门户网站上玩过各种选项.我跟着oauth2 outlook游乐场.但我仍然无法通过这条消息.我怎么能弄清楚这里发生了什么?
请求
我尝试了不同的方法来做这个请求.最简单的就是这一个:
cfhttp(method="POST", charset="utf-8", url="https://login.microsoftonline.com/common/oauth2/v2.0/token", result="result") {
cfhttpparam(name="Content-Type", type="header", value="application/x-www-form-urlencoded");
cfhttpparam(name="grant_type", type="formfield", value="authorization_code");
cfhttpparam(name="code", type="formfield", value="M090efafb-1ce6-1d54-fda7-e48f57c33cba");
cfhttpparam(name="scope", type="formfield", value="openid offline_access profile https://outlook.office.com/mail.read https://outlook.office.com/mail.read.shared https://outlook.office.com/mail.readwrite https://outlook.office.com/mail.readwrite.shared https://outlook.office.com/mail.send https://outlook.office.com/mail.send.shared");
cfhttpparam(name="redirect_uri", type="formfield", value="#URLencode('https://bizz.bmk-is.nl/')#");
cfhttpparam(name="client_id", type="formfield", value="cdee5a0a-a409-4c41-9572-726c5bdbe93e");
cfhttpparam(name="client_secret", type="formfield", value="[HIDDEN VALUE]");
}
## NEW EDIT ##
我将在这里发布更多信息.首先,这是我正在使用的:
response_url = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
response_url = "#response_url#?response_type=code";
response_url = "#response_url#&client_id=cdee5a0a-a409-4c41-9572-726c5bdbe93e";
response_url = "#response_url#&redirect_url=#URLencode('https://bizz.bmk-is.nl/')#";
response_url = "#response_url#&scope=openid offline_access profile";
response_url = "#response_url# https://outlook.office.com/mail.read";
response_url = "#response_url# https://outlook.office.com/mail.read.shared";
response_url = "#response_url# https://outlook.office.com/mail.readwrite";
response_url = "#response_url# https://outlook.office.com/mail.readwrite.shared";
response_url = "#response_url# https://outlook.office.com/mail.send";
response_url = "#response_url# https://outlook.office.com/mail.send.shared&prompt=login";
这是我现在得到的错误:
“error”:“invalid_request”,“error_description”:“AADSTS90102:’redirect_uri’值必须是有效的绝对Uri.
最佳答案 您可能需要对“redirect_uri”进行URL编码.
以下是MS Outlook入门页面的示例.请注意URI上的编码:
GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=<CLIENT ID>&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F&response_type=code&scope=openid+Mail.Read
然后获取AccessToken:
POST https://login.microsoftonline.com/common/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=AwABAAAA...cZZ6IgAA&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F&client_id=<CLIENT ID>&client_secret=<CLIENT SECRET>