Last active
August 21, 2018 20:37
-
-
Save Protome/9675677e35b683af1bdbb8f839cf0525 to your computer and use it in GitHub Desktop.
oAuth iOS Login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func loginToGoodreadsAccount(sender: UIViewController) { | |
let oauthswift = OAuth1Swift( | |
consumerKey: [Replace with your Key], | |
consumerSecret: [Replace with your Secret], | |
requestTokenUrl: "https://www.goodreads.com/oauth/request_token", | |
authorizeUrl: "https://www.goodreads.com/oauth/authorize?mobile=1", | |
accessTokenUrl: "https://www.goodreads.com/oauth/access_token" | |
) | |
oauthswift.allowMissingOAuthVerifier = true | |
oauthswift.authorizeURLHandler = SafariURLHandler(viewController: sender, oauthSwift: self.oauthswift!) | |
let _ = oauthswift.authorize( | |
withCallbackURL: URL(string: "YourAppName://oauth-callback/goodreads")!, | |
success: { credential, response, parameters in | |
//You're auth'd! | |
//I recommend storing the credentials (SECURELY) so you don't need to do this every time. | |
//If you have them stored you can do | |
//oauthswift.client.credential.oauthToken = [stored token] | |
//oauthswift.client.credential.oauthTokenSecret = [stored secret] | |
}, | |
failure: { error in | |
print( "ERROR ERROR: \(error.localizedDescription)", terminator: "") | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment