我目前正在嘗試使用outlook郵件服務來獲取聯繫人/約會和郵件。但是我偶然發現了一個問題。展望OAuth2不能重定向到應用程序
我使用OAuth2Swift作爲庫,使我所有的OAuth調用,因爲我正在集成多個服務。
然後我創建了一個Constants
文件,它看起來像這樣
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)
我創建的Outlook應用程序上https://apps.dev.microsoft.com
生成我的鑰匙和描述祕密並將其填充到我的應用程序中。
我將mobile application
平臺添加到我的應用程序。它告訴我使用重定向URI urn:ietf:wg:oauth:2.0:oob
所以我的代碼授權看起來像這樣
@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)")
}
)
}
當我運行代碼,我第一次看到一個屏幕,進入我的郵箱/密碼
。當我輸入我的郵件時,它會將我重定向到一個不同的頁面/門戶,我可以輸入我的密碼。當我輸入密碼時,它會顯示權限屏幕。
,只要我打yes
它會給我一個錯誤說「由於地址無效,Safari無法打開網頁」。我很確定這與redirect URI
有關,但我不知道該如何解決這個問題。
我希望有人能夠幫助我這個!
我加入,但試圖與Outlook登錄時,它沒有任何區別了同樣的信息顯示出來 – NoSixties