Google authentication with redirect not working

3,255 views
Skip to first unread message

g...@testim.io

unread,
Dec 24, 2015, 9:51:43 AM12/24/15
to Firebase Google Group
I am trying to create a login flow for my single page web app with redirect. I am using the JS SDK. I am using the Google authentication with redirect but I can't get it to work. I have two flows:

First, User presses Login button I then call

ref.authWithOAuthRedirect("google", reject, {scope: 'email'});

I am redirected to google.com, finish the authentication, redirected back to my app with a query parameter __firebase_request_key. But then nothing... both ref.getAuth() and ref.onAuth(function(authData){}) return authData == null.


Second, App starts if a user is already logged-in I would like to get the token and call ref.authWithCustomToken(...) without redirect or any action needed from the user


Please advice


Thanks

Gil


Kato Richardson

unread,
Dec 24, 2015, 10:41:29 AM12/24/15
to Firebase Google Group
Hi Gil,

If the user is already logged in, you wouldn't need to call anything other than onAuth() to detect login state. See persisting user auth state and monitoring user auth state.

authWithCustomToken() is for creating your own auth workflow and signing your own tokens. Not for persisting auth state on restart.

If these aren't working for you, then you'll need to provide a smallish repro and all the details needed to recreate the same conditions (e.g. are you using Ionic? Phonegap? Versions? Steps? Sample data?). I'd also recommend checking the console for errors and turning on debug logging:

JS:  Firebase.enableLogging(true);
iOS:  [Firebase setLoggingEnabled:YES];
Android:  Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);

☼, Kato





--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/d748a55c-012f-4e77-9b2e-6631ee13966f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

g...@testim.io

unread,
Dec 28, 2015, 6:11:32 AM12/28/15
to Firebase Google Group


On Thursday, December 24, 2015 at 5:41:29 PM UTC+2, Kato Richardson wrote:
Hi Gil,

If the user is already logged in, you wouldn't need to call anything other than onAuth() to detect login state. See persisting user auth state and monitoring user auth state.

authWithCustomToken() is for creating your own auth workflow and signing your own tokens. Not for persisting auth state on restart.

If these aren't working for you, then you'll need to provide a smallish repro and all the details needed to recreate the same conditions (e.g. are you using Ionic? Phonegap? Versions? Steps? Sample data?). I'd also recommend checking the console for errors and turning on debug logging:

JS:  Firebase.enableLogging(true);
iOS:  [Firebase setLoggingEnabled:YES];
Android:  Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);

☼, Kato



Hey Kato, 

I am using a web app which in some scenarios is wrapped in a chrome extension as well. I tried the onAuth flow but I got null as authData. I am referring to the second entrance into my app after token auth redirect. I read throughly all the documentation and I don't think it covers full auth with redirect flow. If you can provide an example it will be best.

Thank again
Gil

Jacob Wenger

unread,
Dec 28, 2015, 12:51:49 PM12/28/15
to fireba...@googlegroups.com
Hey there,

I'm not sure if this is also you, but there is a similar thread going on in the AngularFire repo. As mentioned in that issue, we really need a repro to help out here. You say you are using this in a Chrome extension, which is probably not going to work that great. I don't remember the specifics, but I think auth in a Chrome extension does not work. Kato may be able to comment on that in more detail.

As for an example of authWithOAuthRedirect(), here is some quick pseudo-code:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");

// On first page load, this will get called with null
// Upon redirect, this should get called with some actual authData
ref.onAuth(function(authData) {
  if (authData) {
    console.log("Logged in as:", authData.uid);
  } else {
    console.log("Logged out");
  }
});

// This should get called upon clicking a button of some sort
ref.authWithOAuthRedirect("twitter", function(error) {
  if (error) {
    console.log("Authentication Failed!", error);
  } else {
    // We'll never get here, as the page will redirect on success
  }
});

Hope that helps,
Jacob

Gil Ochayon

unread,
Dec 28, 2015, 4:13:41 PM12/28/15
to fireba...@googlegroups.com
Hey Jacob,

will give it a try and update.

Thanks
Gil

--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/SknsQu9tbnY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Gil Ochayon
V.P R&D
Testim.io

Reply all
Reply to author
Forward
0 new messages