How to embed Google Login in WkWebView by switching to SFSafariViewController

I have iOS App

one that basically launches a mobile site with WkWebView

. On the mobile website, users can sign in with a Google account.

Due to the fact that google will not allow WebViews to use Google Sign in anymore, how can I login for my users?

I am thinking of two solutions:

  • Intercept the google url (account.google.com/) and open SFSafariViewController

    and then somehow get a callback in my WkWebView?

    1. Intercept the google login url and use Google Sign in SDK

      that will be passed to SFSafariViewController

      but will only give me a userToken that I will need to send to my site and authenticate the user to the server.

Is there an easy way to authenticate a user without using tokens?

+3


source to share


1 answer


I solved it.

Basically, when WkWebkit runs a URL account.google.com

, it intercepts it and runs Google's own login library, which launches SFSafariViewController

(in iOS 9+, reverts to WebView in previous versions). When the user is done logging in, I get the url of my application, which I process in the application submission, and I get the user information.



The serverAuthcode appears in the custom object, which I need to send to my backend server so that it authenticates the google user. (I am basically re-creating the oauth callback url that the server expects)

0


source







All Articles