0

We have a web app which has two single sign-on options sign-in with apple and sign-in with google which all works fine in the browser. On iOS we have this web app in WKWebview app shell in which we use ASWebAuthenticationSession for sign-in with google.

The problem comes here only when the user has 2 factor authentication on his/her google account, the ASWebAuthenticationSession window doesn't close after 2 step verification, It loads the web app in its own content.

some how it seems like the ASWebAuthenticationSession configuration prefersEphemeralWebBrowserSession = true gets lost in the process.

Anyone with any Idea on how we can fix this problem?

Thanks.

here is the swift code

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    guard let url = navigationAction.request.url else {
      decisionHandler(.cancel)
      return
    }
    if(Functions.getParameter(url: url.absoluteString, param: “code”) != nil){
      authSession.cancel() // close login window
      ......*webView load url*
    }
    else{
      if let url = webView.url, url.absoluteString.starts(with: “https://accounts.google.com”){
        let callbackScheme = “https”
        authSession = ASWebAuthenticationSession(url: url, callbackURLScheme: callbackScheme, completionHandler: { (callbackURL, error) in
          return
        })
        authSession.presentationContextProvider = self
        authSession.prefersEphemeralWebBrowserSession = true
        authSession.start()
        decisionHandler(.cancel)
        return
      }
    }
   decisionHandler(.allow)
  }
Joel S
  • 3
  • 3
  • Usually the login completion should be the browser invoking the custom scheme URL of your app or universal links via redirect. The IdP would be to blame in case it lost in the process. – mr5 May 25 '23 at 07:52

0 Answers0