Facebook4, Firebase, getting null email - ionic-framework

I have an app built with ionic and firebase. I am using facebook4 cordova plug in to log in with facebook. When they log in, I get the name and email address of the user.. However in some devices, I am getting null emails addresses. When I go to auth section in firebase, I see their email address as (-) empty although the displayname is returning correct. Here is my code.
facebookConnectPlugin.login(['email', 'public_profile', 'user_friends'], //first argument is an array of scope permissions
function (userData) {
if (userData.authResponse) {
facebookConnectPlugin.api('me/?fields=email,name,first_name,last_name', ["public_profile"],
function (inforesult) {
facebookConnectPlugin.getAccessToken(function (token) {
//alert("Token: " + token);
var credential = firebase.auth.FacebookAuthProvider.credential(token);
firebase.auth().signInWithCredential(credential).then(function (result) {
alert(JSON.stringify(result)); // the email field is null.
$scope.myprofile = result;
}).catch(function (error) {
// Handle Errors here.
alert(error.message);
/ ...
});
});
});
}
},
function (error) {
alert(error);
}
)
Is there some kind of permissions I am missing?

They may not have their email approved, or they login with their mobile phones. You can´t be sure that every user got an email.

Related

Inconsistent Contacts.getPermissions() response with #capacitor-community/contacts plugin

In my Angular 13 Ionic 6 app, I am attempting to fetch all contacts for the user, in a component:
import { Contacts } from '#capacitor-community/contacts';
ngOnInit() {
Contacts.getPermissions().then((response) => {
console.log('Contacts permission response: ', response);
if (response.granted) {
console.log('Granted permissions for contacts');
this.dialogs.openLoader('Your contacts are coming up...');
Contacts.getContacts().then((result) => {
this.foundContacts = true;
console.log('Got contacts result: ', result);
this.contacts = result.contacts;
this.selectedContactName = '';
this.dialogs.closeLoader();
});
}
});
}
The response coming back from the getPermissions() promise is inconsistent:
Upon initial run of the app, when the permissions dialog opens for the user, it returns this (console.log output):
Contacts permission response: {contacts: 'granted'}
Re-openning the component without the permissions dialog box opening, it looks different:
Contacts permission response: {granted: true}
In the first case, the IF test (response.granted) fails, which is not the expected behavior.
What is happening here?
It’s a known issue that has been reported on their issue tracker
https://github.com/capacitor-community/contacts/issues/57

Firebase Auth - forgotten password with phone auth

My app currently allows a user to create their Firebase account via phone number. I'm currently trying to figure out the logic for a password reset when the user created their account with a phone number rather than email.
The only reset password functionality i can find on the Firebase docs requires an email address.
Any help is appreciated!
You can use verifyPhoneNumber:UIDelegate:completion: to send the users another SMS message for verification and then sign in using the verificationID.
Official doc on how to do that -> https://firebase.google.com/docs/auth/ios/phone-auth#send-a-verification-code-to-the-users-phone.
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in
if let error = error {
self.showMessagePrompt(error.localizedDescription)
return
}
// Sign in using the verificationID and the code sent to the user
// ...
}
OR
If you have a server, you can use Firebase admin SDK, available in Node.js, Java, Python, Go, and C#, to update the user's password property just with user's uid.
Example in Node.js:
admin.auth().updateUser(uid, {
password: "YOUR_NEW_PWD"
})
.then((userRecord) => {
console.log('Successfully updated user', userRecord.toJSON());
})
.catch((error) => {
console.log('Error updating user:', error);
});

How do I just get an email address after authenticating with oAuth2? - google-api-nodejs-client

I am trying to just get an email address after authenticating with oAuth2. After I get a code when I validate with a google account, I go and get the user from Google Plus, like this:
let oAuth2Client = new auth.OAuth2(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_CLIENT_CALLBACK);
const tokens = await getToken(oAuth2Client, code);
oAuth2Client.setCredentials(tokens);
plus('v1').people.get({ userId: 'me', auth: oAuth2Client }, function(err, response) {
.... This repsonse is the full user object from Google Plus
});
How do I just get the email address, or a list of email addresses? I don't want all the other Google Plus info. I have already set my scope to email, but I still get lots of other information. I am assuming that I need to make a request to something other than plus, but I can't find what to do in the documentation.
If you have set email scope (https://www.googleapis.com/auth/userinfo.email), you can use oauth2("v2").userinfo.v2.me.get :
var google = require('googleapis');
....
google.oauth2("v2").userinfo.v2.me.get({
auth: oAuth2Client
}, function(e, profile) {
if ("email" in profile) {
console.log(profile.email);
} else {
console.log("scope email not set");
}
});

can't get gmail user displayname via firebase3 login in Ionic platform

I am working on google auth with firebase signinwithcredential. I first used cordovaoath to get the id token and sign it in with firebase. I specifically indicated in my code that I would like to get the displayName, but it always come back null. I was wondering anyone have faced the same problem?
this.loginWithGoogle = function loginWithGoogle() {
$cordovaOauth.google("mygoogleclient id here", ["https://www.googleapis.com/auth/calendar","https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile","https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/plus.login", "https://www.googleapis.com/auth/drive"]).then(function (result) {
// "email", "profile",
console.log("first come here to oath");
console.log("Response Object -> " + JSON.stringify(result));
var unsubscribe = firebase.auth().onAuthStateChanged(function (firebaseUser) {
unsubscribe();
// Check if we are already signed-in Firebase with the correct user.
// Build Firebase credential with the Google ID token.
var credential='';
credential = firebase.auth.GoogleAuthProvider.credential(
result.id_token);
// Sign in with credential from the Google user.
firebase.auth().signInWithCredential(credential).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
});
});
}, function (error) {
console.log("Error -> " + error);
});
};
sreenshot of my returned result
You should request an access token, and not an ID token, if you are requesting additional scopes.
To fix your code, change this line:
var credential = firebase.auth.GoogleAuthProvider.credential(
null, result.access_token); // <- access_token

verify email using accounts.ui package

I want to send a verification email when some user is created. I use the accounts-password package, so any Accounts methods are called in my code.
I read in documentation that I need to call:
Accounts.sendVerificationEmail(userId, [email])
but the problem is that I don't know when to call it.
I tried to call in the callback function of Accounts.onCreateUser(func) but the user had not been created yet in the database.
Any ideas?
on the serverside:
Accounts.config({sendVerificationEmail: true, forbidClientAccountCreation: false});
got the answer from the comments above.
sendVerificationEmail is only available server-side. What I usually do is to use a setInterval inside onCreateUser to wait for Meteor to create the user before sending an email.
Read More: Verify an Email with Meteor Accounts.
// (server-side)
Accounts.onCreateUser(function(options, user) {
user.profile = {};
// we wait for Meteor to create the user before sending an email
Meteor.setTimeout(function() {
Accounts.sendVerificationEmail(user._id);
}, 2 * 1000);
return user;
});
You need specify mail in enviroment variables.
Then use Accounts.sendVerificationEmail(userId, [email]) in callback of Account.onCreateUser sorry for mistake and delay.
Like this (below is full example js file):
Template.register.events({
'submit #register-form' : function(e, t) {
e.preventDefault();
var email = t.find('#account-email').value
, password = t.find('#account-password').value;
// Trim and validate the input
Accounts.onCreateUser({email: email, password : password}, function(err){
if (err) {
// Inform the user that account creation failed
} else {
// Success. Account has been created and the user
// has logged in successfully.
Accounts.sendVerificationEmail(this.userId, email);
}
});
return false;
} });
if(Meteor.isServer){
Meteor.startup(function(){
process.env.MAIL_URL='smtp://your_mail:your_password#host:port'
}
}
I refered to this pages :
http://blog.benmcmahen.com/post/41741539120/building-a-customized-accounts-ui-for-meteor
http://sendgrid.com/blog/send-email-meteor-sendgrid/
How come my Meteor app with accounts package is not sending a verification email?