Goodreads Developers discussion

51 views
questions > OAuth in iOS

Comments Showing 1-10 of 10 (10 new)    post a comment »
dateDown arrow    newest »

message 1: by Navarjun (last edited Aug 20, 2018 06:24PM) (new)

Navarjun | 6 comments Hello everyone

I am trying to get OAuth work on iOS… I tried a lot, believe me I have been trying since yesterday, and it's already today evening. There is an library that I found, but I cannot use it as it uses deprecated methods… and Apple will reject my app as soon as I submit.

I followed the documentation on OAuth website. There is also a link that I followed:
https://www.cubrid.org/blog/dancing-w...

Can someone document the requests needed to get OAuthorization for goodreads API.
I am looking for following things:
- What requests do I need to make? (and in what order)
- What should be the link I send users to?
- What are the headers/url parameters/body parameters that I need to send for each request?
- What is the "base signature string" for each request?

Thanks in advance!


message 2: by Kieran (new)

Kieran (protome) | 10 comments Are you writing in Swift?
I used OAuthSwift and just followed the documentation on their github to get it up and running: https://github.com/OAuthSwift/OAuthSwift


message 3: by Navarjun (new)

Navarjun | 6 comments Can you provide the sample code which uses SafariViewController?


message 4: by Kieran (new)

Kieran (protome) | 10 comments Navarjun wrote: "Can you provide the sample code which uses SafariViewController?"

Here you go. The SafariURLHandler function in OAuthSwift creates a SafariViewController for you (you can even set a delegate to it if you want to handle failure states better)

https://gist.github.com/Protome/96756...


message 5: by Navarjun (new)

Navarjun | 6 comments For me the SafariViewController is never popped back… and neither success or failure is called. Does that happen for you?

I know I am missing something really stupid


message 6: by Navarjun (new)

Navarjun | 6 comments Kieran wrote: "Navarjun wrote: "Can you provide the sample code which uses SafariViewController?"

Here you go. The SafariURLHandler function in OAuthSwift creates a SafariViewController for you (you can even set..."


Also, what is AuthStorageService in the sample code?

Thanks a lot for doing this.


message 7: by Kieran (new)

Kieran (protome) | 10 comments Navarjun wrote: "For me the SafariViewController is never popped back… and neither success or failure is called. Does that happen for you?

I know I am missing something really stupid"


That's weird. Have you set up your AppDelegate/info.plist to respond to Return URLs like at the start of the How To section of https://github.com/OAuthSwift/OAuthSwift ? That should allow OAuthSwift to handle it automatically.

Navarjun wrote: "Also, what is AuthStorageService in the sample code?

Thanks a lot for doing this. "


Oh, I created an AuthStorageService that saves the Auth Token & Secret in the keychain and retrieves them again later. It just saves the app needing a login every time it's reopened. I meant to remove it from the gist!


message 8: by Navarjun (new)

Navarjun | 6 comments Have you set up your AppDelegate/info.plist to respond to Return URLs like at the start of the How To section of https://github.com/OAuthSwift/OAuthSwift ? That should allow OAuthSwift to handle it automatically.

Yes, I did that… but it's not working :(


message 9: by Navarjun (new)

Navarjun | 6 comments Oh, great!
It worked now… I realised my mistake… there was a typo in the AppDelegate String…


func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.host == "oauth-calback") {
OAuthSwift.handle(url: url)
}
return true
}


callback was spelled calback

Thanks a lot for helping me figure this out.


message 10: by Kieran (new)

Kieran (protome) | 10 comments Navarjun wrote: "Oh, great!
It worked now… I realised my mistake… there was a typo in the AppDelegate String…


func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] ..."


Haha! Happens to the best of us :)
Best of luck with your app!


back to top