0

I am trying to use ASWebAuthenticationSession web view. After the authentication is complete, the session completion handler is not being called. Hence, the web view doesn't dismiss.

guard let authURL = URL(string: "https://github.com/login/oauth/authorize?client_id=<client_id>/") 
else { return }
let scheme = "octonotes"
session = ASWebAuthenticationSession.init(url: authURL, callbackURLScheme: scheme, completionHandler: { callbackURL, error in
       // Handle the callback.
       print(callbackURL!)
       print(error!)      
        })
session?.presentationContextProvider = self
session?.start()

I have set the callback url scheme in info.plist. The same is updated in Targets -> info -> URL Types It looks like: URL Types

After running the above code, ASWebAuthenticationSession web view is presented, which provides user with sign in page. Once the authentication is complete, web view does not dismiss unlike WKWebView. There is cancel option on top left of the web view, it calls the completion handler with error.

Is there a way to dismiss webview after the authentication session is complete?

Shraddha
  • 1
  • 2
  • I am trying ASWebAuthenticationSession on watch OS and having the same issue, but I can not find URL scheme setting on watchOS – Bill Chan Mar 04 '23 at 10:11

1 Answers1

0

It looks like you're missing the redirect URI in your authURL - so GitHub doesn't know where to redirect the successful auth to.

Try this:

let scheme = "octonotes"
guard let authURL = URL(string: "https://github.com/login/oauth/authorize?client_id=<client_id>&redirect_uri=\(scheme)://authcallback")

Bear in mind you may be missing some other parameters too, take a look here for the other ones you can provide https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/#redirect-urls

Workshed
  • 236
  • 1
  • 8