ios - Outlook OAuth2 无法重定向到应用程序
<p><p>我目前正在尝试使用 Outlook 邮件服务来获取联系人/约会和邮件。但是我偶然发现了一个问题。</p>
<p>我正在使用 <a href="https://github.com/OAuthSwift/OAuthSwift" rel="noreferrer noopener nofollow">OAuth2Swift</a>因为我正在集成多个服务,所以作为库来进行我所有的 OAuth 调用。</p>
<p>我创建了一个 <code>URL 方案</code>,如他们的 <code>README</code> 中所述
<a href="/image/mBqsB.png" rel="noreferrer noopener nofollow"><img src="/image/mBqsB.png" alt="enter image description here"/></a> </p>
<p>然后我创建了一个 <code>Constants</code> 文件,看起来像这样</p>
<pre><code>struct Consumer {
let consumerKey: String
let consumerSecret: String
let authorizeURL: String
let accessTokenURL: String
let responseType: String?
let requestTokenURL: String?
}
let Outlook = Consumer(
consumerKey: "",
consumerSecret: "",
authorizeURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
accessTokenURL: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
responseType: "code",
requestTokenURL: nil)
</code></pre>
<p>我在 <a href="https://apps.dev.microsoft.com" rel="noreferrer noopener nofollow">https://apps.dev.microsoft.com</a> 上创建了一个 Outlook 应用程序<br/>
生成我的 key 和 secret 并将它们填写在我的应用程序中。</p>
<p>我将 <code>移动应用程序</code> 平台添加到我的应用程序中。这告诉我使用重定向URI <code>urn:ietf:wg:oauth:2.0:oob</code></p>
<p>所以我的授权代码如下所示</p>
<pre><code>@IBAction func btn_Outlook(_ sender: Any) {
let oauthOU = OAuth2Swift(
consumerKey: Outlook.consumerKey,
consumerSecret: Outlook.consumerSecret,
authorizeUrl: Outlook.authorizeURL,
accessTokenUrl: Outlook.accessTokenURL,
responseType: Outlook.responseType!)
oauthOU.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthOU)
oauthOU.authorize(
withCallbackURL: "urn:ietf:wg:oauth:2.0:oob",
scope: "https://outlook.office.com/Mail.ReadWrite https://outlook.office.com/Mail.Send https://outlook.office.com/Calendars.ReadWrite https://outlook.office.com/Contacts.ReadWrite https://outlook.office.com/Tasks.ReadWrite",
state: state,
success: { credential, response, parameters in
print("logged in with \(credential), with response \(response) and parameters \(parameters)")},
failure: { error in
print("error occured \(error.localizedDescription)")
}
)
}
</code></pre>
<p>当我运行代码时,我首先会看到一个输入我的邮件/密码的屏幕。当我输入我的邮件时,它会将我重定向到另一个页面/门户,我可以在其中输入我的密码。当我输入密码后,它会显示权限屏幕。</p>
<p> <a href="/image/aF9Z4.png" rel="noreferrer noopener nofollow"><img src="/image/aF9Z4.png" alt="enter image description here"/></a> </p>
<p>当我点击 <code>yes</code> 时,它会给我一个错误提示“Safari 无法打开页面,因为地址无效。”我很确定这与 <code>redirect URI</code> 有关,但我不确定如何才能真正解决这个问题。</p>
<p>我希望有人能够帮助我解决这个问题!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您忘记在 URL 方案设置中指定标识符 <code>urn:ietf:wg:oauth:2.0:oob</code>(见第一张图片:没有设置标识符)</p></p>
<p style="font-size: 20px;">关于ios - Outlook OAuth2 无法重定向到应用程序,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42644818/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42644818/
</a>
</p>
页:
[1]