I am working on a project where I am implementing the OAuthSwift library to connect to several different social networking sites that use both OAuth1 and OAuth2.
I have the application set up to load a web view that takes me to my social networking site, but I can't get the application to redirect back. Once I load my credentials, it asks for me to give permission to authorize the application, but once I do, it loads my homepage for the social networking site.
I can navigate back to the application, but it does not register that it has received permission to access my account.
This is my first time working with OAuth and I find the callback URL to be confusing.
I would appreciate some help explaining how to get the web view to redirect back to my application and how to set up the URL for the app.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func postToTumblr(sender: AnyObject) {
let oauthSwift = OAuth1Swift(
consumerKey: "consumerKey",
consumerSecret: "secretKey",
requestTokenUrl: "https://www.tumblr.com/oauth/request_token",
authorizeUrl: "https://www.tumblr.com/oauth/authorize",
accessTokenUrl: "https://www.tumblr.com/oauth/access_token"
)
oauthSwift.authorizeWithCallbackURL(NSURL(string: "com.myCompany.sampleApp")!,
success: { credential, response in
// post to Tumblr
print("OAuth successfully authorized")
}, failure: {(error:NSError!) -> Void in
self.presentAlert("Error", message: error!.localizedDescription)
})
}
func presentAlert(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
application:openURL...
method in your app delegate? – Edvard