Outlook OAuth2无法重定向到应用程序

时间:2017-03-07 09:43:02

标签: ios swift oauth outlook

我目前正在尝试使用Outlook邮件服务来获取联系人/约会和邮件。但是我偶然发现了一个问题。

我正在使用OAuth2Swift作为库来进行所有OAuth调用,因为我正在集成多个服务。

我创建了URL scheme,如README中所述 enter image description here

然后我创建了一个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)

我在https://apps.dev.microsoft.com上创建了一个outlook的应用程序 生成我的密钥和秘密,并在我的应用程序内填充它们。

我将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)")
            }
            )
        }

当我运行代码时,我首先得到一个屏幕来输入我的邮件/密码。当我输入邮件时,它会将我重定向到另一个页面/门户网站,我可以在其中输入我的密码。当我输入密码后,它会显示权限屏幕。

enter image description here

一旦我点击yes,它就会给我一个错误,说“Safari无法打开该页面,因为地址无效。”我很确定这与redirect URI有关,但我不知道如何解决这个问题。

我希望有人能够帮助我解决这个问题!

2 个答案:

答案 0 :(得分:0)

我认为您忘记在URL方案设置中指定标识符urn:ietf:wg:oauth:2.0:oob(请参阅第一张图片:没有设置标识符)

答案 1 :(得分:0)

我认为您忘记在OAuthSwift库中处理AppDelegate中的chennai = {"name": "Kumar", "Department": "Sales", "Age": 39,"Salary": 20} mumbai = {"name": "Suresh","Department": "Finance", "Age": 53,"Salary": 35} delhi = {"name": "Babu", "Department": "QC", "Age": 28,"Salary": 10} kolkata = {"name": "Satish","Department": "Production","Age": 34,"Salary": 15} madurai = {"name": "Dev", "Department": "Management","Age": 45,"Salary": 23} hyderabad = {"name": "Rani", "Department": "Marketing", "Age": 46,"Salary": 25} bengalore = {"name": "Devi", "Department": "Production","Age": 24,"Salary": 5} cochin = {"name": "Sarath","Department": "Production","Age": 26,"Salary": 12} jaipur = {"name": "Senu", "Department": "Production","Age": 25,"Salary": 8} shimla = {"name": "Kumari","Department": "Management","Age": 37,"Salary": 20} lucknow = {"name": "Sanjay","Department": "Marketing", "Age": 52,"Salary": 30} employ = [chennai,mumbai,delhi,kolkata,madurai,hyderabad,bengalore,cochin,jaipur,shimla,lucknow] #Finding Production unit salary expenditure for x in employ: sums = 0 if x ["Department"] == 'Production': print x["Salary"] 了!您可以在AppDelegate中处理回调,如下所示。

redirect URI