How to setup the callback URL in the OauthSwift library

ぃ、小莉子 提交于 2019-12-04 12:41:22

After speaking with some people at my company and having them look over the library, we were able to resolve the issue as follows:

The OAuthSwift library drops the "com.myCompany" part of the URL scheme. When it is looking for the callback URL, it is looking for the name of the application followed by "://oauth-callback".

So instead of:

oauthSwift.authorizeWithCallbackURL(NSURL(string: "com.myCompany.sampleApp")!

it was looking for:

oauthSwift.authorizeWithCallbackURL(NSURL(string: "tumblrsampleapp://oauth-callback")!

I also had to register the URL scheme in the info.plist as:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>tumblrsampleapp</string>
        </array>
    </dict>
</array>

Lastly, I had to add the following method to the App Delegate:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    OAuth1Swift.handleOpenURL(url)
    return true
}

This has resolved the issue and the app now authenticates properly and returns back to my application.

I hope this is useful to anyone else trying to implement OAuth1 using the OAuthSwift library.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!