Firebase and angularFire - getting email from google authentication works with $ authWithOAuthPopup but fails $ authWithOAuthRedirect
The following code snippet works, unless the user's browser (iOS with Chrome for example) sends it to the $ authWithOAuthRedirect block - then it doesn't work.
And fail, I mean the $ authWithOAuthRedirect method and the user can approve the authentication, but he cannot submit the scope to Google correctly, and the email is not prompted.
var provider = 'google';
var scope = {scope:'email'};
var auth = $firebaseAuth(FirebaseInstance.firebase);
auth.$authWithOAuthPopup(provider, scope).then(function (authData, error) {
if (error && error.code === "TRANSPORT UNAVAILABLE") {
auth.$authWithOAuthRedirect(provider, function(error) {}, scope);
}
});
Simplified, this code won't be able to request the user's email:
var provider = 'google';
var scope = {scope:'email'};
var auth = $firebaseAuth(FirebaseInstance.firebase);
auth.$authWithOAuthRedirect(provider, function(error) {}, scope);
Thank you for your help!
+3
source to share
1 answer
I think the problem is you are using the syntax for the angular version: Firebase.authWithOAuthRedirect (provider [, callback, scope])
You must be using AngularFire version: $ firebaseAuth. $ authWithOAuthRedirect (provider [, options])
This version returns a promise, so your simplified code should look like this:
var provider = 'google';
var scope = {scope:'email'};
var auth = $firebaseAuth(FirebaseInstance.firebase);
auth.$authWithOAuthRedirect(provider, scope).then(function (authObject) {
// Handle success
}, function (error) {
// Handle error
});
+5
source to share