Callback URL not calling completionHandler

725 views Asked by At

I’m trying to use ASWebAuthentication to facilitate the authentication process with Oauth 1.0. After the user enters their credentials and approves my application, oauth provider uses the redirect_url I passed in, com.me.appName:/returnToApp and the Safari window looks something like this:

Safari Image

Here's my code:

func getAuthTokenWithWebLogin(context: ASWebAuthenticationPresentationContextProviding) {
      let callbackUrlScheme = “scheme:/returnToApp"
      let authURL = URL(string: Constants.authURL)
     

      guard authURL != nil else{return}
      let webAuthSession = ASWebAuthenticationSession.init(url: authURL!, callbackURLScheme: callbackUrlScheme, completionHandler: { (callBack:URL?, error:Error?) in

          // handle auth response
          guard error == nil, let successURL = callBack else {
              return
          }

          let oauthToken = NSURLComponents(string: (successURL.absoluteString))?.queryItems?.filter({$0.name == "code"}).first

          // Do what you now that you've got the token, or use the callBack URL
          print(oauthToken ?? "No OAuth Token")
      })
      
      // New in iOS 13
      webAuthSession.presentationContextProvider = context
      // Kick it off
      webAuthSession.start()
  }

I don't think it's an issue with ASWebAuthentication, since I've had the same problem when I tried using third party library OauthSwift

1

There are 1 answers

0
The Swift Coder On BEST ANSWER

My bad; I didn't realize that the callbackURL must be in myApp:// format, while I had mine as myApp:/ (single slash) thinking this would also work.