重定向 URI 对 Outlook MAIL REST 无效 API
Redirect URI not valid with Outlook MAIL REST API
预知
我有一个正在运行的 ColdFusion 应用程序(基于 Web),其中实施了完整的 Google Oauth2 验证过程。这很好用,我可以通过 post 命令检索电子邮件。现在我想对微软的 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 展望游乐场。但是我仍然无法通过此消息。我怎样才能弄清楚这里发生了什么?
请求
我尝试了不同的方法来完成请求。最简单的就是这个:
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]");
}
## 新编辑 ##
我将在此处 post 提供更多信息。首先,这是我正在使用的 get:
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。
您可能需要 URL 编码您的 'redirect_uri'。
这是 MS Outlook REST 入门页面中的示例。注意 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>
天哪,我找到了!我四处搜索并使用重定向 uri,这时我注意到在 get 中我将其命名为 "redirect url" 并在 post "redirect uri" 中。将其更改为 uri,现在可以正常工作了!超好。仍然很奇怪,我没有收到重定向 url 什么都没有的错误,但是嘿,我很高兴它能正常工作。
预知
我有一个正在运行的 ColdFusion 应用程序(基于 Web),其中实施了完整的 Google Oauth2 验证过程。这很好用,我可以通过 post 命令检索电子邮件。现在我想对微软的 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 展望游乐场。但是我仍然无法通过此消息。我怎样才能弄清楚这里发生了什么?
请求
我尝试了不同的方法来完成请求。最简单的就是这个:
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]");
}
## 新编辑 ##
我将在此处 post 提供更多信息。首先,这是我正在使用的 get:
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。
您可能需要 URL 编码您的 'redirect_uri'。
这是 MS Outlook REST 入门页面中的示例。注意 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>
天哪,我找到了!我四处搜索并使用重定向 uri,这时我注意到在 get 中我将其命名为 "redirect url" 并在 post "redirect uri" 中。将其更改为 uri,现在可以正常工作了!超好。仍然很奇怪,我没有收到重定向 url 什么都没有的错误,但是嘿,我很高兴它能正常工作。