Skip to content

Instantly share code, notes, and snippets.

@Protome
Last active August 21, 2018 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Protome/9675677e35b683af1bdbb8f839cf0525 to your computer and use it in GitHub Desktop.
Save Protome/9675677e35b683af1bdbb8f839cf0525 to your computer and use it in GitHub Desktop.
oAuth iOS Login
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