Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

OAuth 2.0 with Swift Tutorial

In this OAuth 2.0 Swift tutorial you will learn how to use two different open source libraries to implement OAuth 2.0 in an iOS app.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/243-oauth-2-0-with-swift-tutorial

What about the iOS 11.0 class SFAuthenticationSession? Wouldn’t it replace those third-party libs?

It is recommended by Apple to use SFAuthenticationSession and you will require it for SSO in iOS 11+, it can certainly help streamline the process of integration. Although you should still be supporting iOS 10 pathway with SafariViewController

Thanks so much for updating the material for the latest version. It’s so much easier to use one of these SDKS for Google or Facebook, but do you think you could do a tutorial on another auth that is not part of an SDK? I am trying to build something with a third party medical record system, and it gets much more problematic when it’s not built in to Oauth.

Maybe it’s just me but I found the UI on the web to be different from the UI shown in this tutorial. Not sure why, but you may want to check quick to see if it changed.

@owenb Do you have any feedback about this? Thank you - much appreciated! :]

Hi rafaelcsa,
Correct, using Apple’s SFAuthenticationSession is the preferred solution for iOS 11 and beyond. We discussed this at RW before updating the tutorial, but felt the 3rd party solutions are still viable.

Hi mashype,
Yes, SFAuthenticationSession is in our ‘Brainstorm’ list and will likely be pulled in as a new tutorial.
Sorry, I can’t give ETA on this :]

Hi, I see your UI is built by AutoLayout, then you change the location by assigning a new value to recognizerView.center. Is that ok? Because I don’t see an official document pointing that. Thank you.

@owenb Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hello vietstone,
Nice question. According to Apple docs, translations work well with AutoLayout. Here is a quote from the developer site:

In iOS 8.0 and later, the transform property does not affect Auto Layout. Auto layout calculates a view’s alignment rectangle based on its untransformed frame.

https://developer.apple.com/documentation/uikit/uiview/1622459-transform

Oh, I don’t see it. But why the docs only write about transform, but not `center? Are they the same?

They aren’t the same. Center is the point to be transformed. Other points can be transformed also.

Hi, as the document writes for transform, I can understand if it’s translation (x, y) in transform for changing position, but you change position by center, so I don’t understand why it does not interfere with AutoLayout. Can you explain more? Thank you.

Im new to this and am confused by two things.

  1. I opened the Incognito project and noticed that it is using Top/Bottom Layout Guides and Constraints. I don’t have that when I create single view applications, I have a safe area instead. This is confusing for me because I think I read somewhere that those Guides and Restraints are deprecated?

  2. I can not run the app. I have not changed anything, but got an error saying that I need a team, so I added myself as a ‘personal team’, now I can’t run it because I get 2 errors:

56 am

@owenb Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi aviate,

  1. Yeah, safe area is recommended over top/bottom guides. It must have been left over from the project it was updated from. Either one will still work for the current version.

  2. Yes, on all downloaded projects (or new Xcode project) you must select your own developer account and add the bundle identifier.

I am attempting to follow your OAuth2Swift piece, but run into an error on the callback in the Application Delegate Oauth2Swift.handle(url: url).

I have my callback url set up just like the tutorial: guard let rwURL = URL(string: "com.devetry.ytp:oauth2Callback") else { return }. But when it comes back,

The error I am getting states that operation could not be complete. My only assumption could be that the callback url is not configured correctly? Is there additional steps I need to take to get the OAuth2Swift.handle(url: url) to succeed?

Hi tannerjuby,
Try “com.devetry.ytp:/oauth2Callback” (with the slash).
Worth a try :slight_smile:

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you! :]