firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Google as an Auth provider doesn't work on iOS saved to homescreen

Open Haroenv opened this issue 9 years ago • 75 comments

[REQUIRED] Describe your environment

  • Operating System version: iOS 10
  • Firebase SDK version: 4.1.3
  • Firebase Product: auth

[REQUIRED] Describe the problem

Steps to reproduce:

  1. Save the app on the homescreen on iOS
  2. make a redirect or popup login with google Auth provider
  3. if redirect:
    • webview is not a "valid user agent"
  4. if popup:
    • gets stuck in Safari about:blank, doesn't open the app again to pass on the token

Relevant Code:

import firebase from "firebase";

const config = {
//...
};

firebase.initializeApp(config);

const googleAuthProvider = new firebaseAuth.GoogleAuthProvider();

firebase.auth().signInWithRedirect(googleAuthProvider);
// or
firebase.auth().signInWithRedirect(googleAuthProvider);

Haroenv avatar Jun 24 '17 21:06 Haroenv

related issue: https://github.com/firebase/quickstart-js/issues/94

Haroenv avatar Jun 24 '17 22:06 Haroenv

This is a known issue and not really Firebase related (in the case of redirect) which is Google sign-in related. Webviews are insecure and Google sign-in no longer works in that environment anymore. Google sign-in recommends using SFSafariViewController for this but homescreen apps cannot run in a SFSafariViewController, instead they always run in a webview environment. As for popups, they won't work for a different reason since Firebase OAuth popup relies on web storage to pass the result back to the app. However homescreen apps do not share the same web storage as the system browser (which is how the popup is opened).

bojeil-google avatar Jun 25 '17 05:06 bojeil-google

I totally understand that, but saving to home screen isn’t something I have control over as an author. Does this really come down to “it’s impossible”?

Haroenv avatar Jun 25 '17 07:06 Haroenv

Unfortunately, it is currently impossible if you wish to use Google Sign in. If you are using other providers, you can use the recommended signInWithRedirect for that mode (it should work).

bojeil-google avatar Jun 26 '17 18:06 bojeil-google

This is a pretty big, deal breaker, any hope/news on this ?

Bretto avatar Jul 13 '17 03:07 Bretto

Sorry, it is out of our control. You need to reach out to the Google OAuth folks about this. I don't think there is currently anyway to get Google sign-in to work in a home screen iOS app.

bojeil-google avatar Jul 13 '17 03:07 bojeil-google

Android is also effected by this issue, this is definitely a deal breaker for pwa

RileyDavidson-Evans avatar Jul 20 '17 15:07 RileyDavidson-Evans

There are still no solution for this problem?

zywyz avatar Aug 31 '17 15:08 zywyz

Have just run into this issue myself, some of our users are trying to launch from iOS bookmarks and are unable to sign in. I appreciate this is not a firebase issue per say but wanted to add my voice here to draw attention that there are more affected users.

I am using firebase web authentication, is there no way to allow login from iOS in this instance?

Thanks

cdharris avatar Sep 03 '17 16:09 cdharris

This makes me sad.

ghost avatar Sep 04 '17 07:09 ghost

Facebook login and other non-Google providers should work in redirect mode only. As I mentioned earlier, it is impossible to get Google sign-in in that iOS homescreen mode. From the Google sign-in perspective, it is coming from an embedded webview which are now blocked.

bojeil-google avatar Sep 04 '17 20:09 bojeil-google

Does anyone know where we can follow the progress on this PWA deal breaker ?

Bretto avatar Sep 04 '17 21:09 Bretto

We would welcome a solution to this problem as well. Unfortunately this is a "deal breaker" for us as well.... I wanted to share on this thread as we are running into this same issue and did not want to be silent about it.

Looking forward to a resolution soon!

mikeatmarvel avatar Oct 23 '17 16:10 mikeatmarvel

How do we upvote a solution?

codercatdev avatar Nov 04 '17 00:11 codercatdev

Does anyone know where we can follow information on how this problem is being treated by either Google OAuth, Apple or Firebase?

Is there a way for firebase to detect if the app is launched from the home screen so we can display an explanation for our users?

mesqueeb avatar Dec 10 '17 23:12 mesqueeb

The iOS embedded webview has a distinct useragent. You can test for that and display a message to the user. Embedded webviews for iOS 9 and above are blocked from accessing the Google OAuth page for security reasons: https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html

bojeil-google avatar Dec 11 '17 08:12 bojeil-google

Why not just:

  var fbAppId = 'XXXXXXXXXXXXXX';
  var fburl = "https://www.facebook.com/dialog/oauth?";
  fburl += "client_id="+fbAppId;
  fburl += "&redirect_uri="+window.location.href;
  window.location.href = fburl;

When popup is not possible, like in Safari?

tcha-tcho avatar Dec 18 '17 22:12 tcha-tcho

@RileyDavidson-Evans Look: https://bugs.chromium.org/p/chromium/issues/detail?id=771418 seems to be fixed in Chrome dev 64.0.3254.2

Actually, I tried https://fir-ui-demo-84a6c.firebaseapp.com/ posted in the thread above with just the latest stable Chrome and couldn't reproduce the endless loop. Maybe someone fixed something behind the scene already?

henrylearn2rock avatar Jan 10 '18 12:01 henrylearn2rock

For me it looks like redirect auth works on https://friendly-pix.com/ on iOS homescreen apps with Google sign-in. But perhaps, since this is an old app, I was grandfathered into an exception.

Popup auth works on Android Homescreen apps.

This is how I implemented an exception just for iOS homescreen apps:

  var signInFlow = 'popup';
  // For iOS full screen apps we use the redirect auth mode.
  if (('standalone' in window.navigator)
      && window.navigator.standalone){
    signInFlow = 'redirect';
  }

  // FirebaseUI config.
  var uiConfig = {
    'signInFlow': signInFlow,
    'signInOptions': [
      firebase.auth.GoogleAuthProvider.PROVIDER_ID,
      firebase.auth.FacebookAuthProvider.PROVIDER_ID
    ]
  };
  var firebaseUi = new firebaseui.auth.AuthUI(firebase.auth());

nicolasgarnier avatar Jan 22 '18 11:01 nicolasgarnier

When I tested today it worked without problems. Was this problem fixed on Apple's side (related to webviews) or Google OAuth side or Firebase side?

mesqueeb avatar Feb 07 '18 01:02 mesqueeb