Facebook login: re-request authorization / re-authenticate


#1

Hi,

Using the plugin cordova-plugin-facebook4, I successfully implemented facebook login.

However, I need the email authorization to be “required” (meaning the user should not attempt login without giving facebook authorization to get his email)
If he doesn’t allow access to email, redirect to login.

This works well so far, BUT when he tries to connect again using facebook (to give him the chance to allow access to email this time), facebook is not asking again for authorization.

I have read online that native sdk make use of the “rerequest” or “reauthentication” callback / paramet.
But apparently all facebook cordova plugin do not have this extra callback/parameter feature.

( for info, parameter mentioned here: https://developers.facebook.com/docs/facebook-login/reauthentication )

Did anyone successfully implement this feature ?

Please help me.


#2

Yep, i have something like that in an ionic2 app :

  reconnectUser(password?: string): any {
	//generate fresh credentials
	if(this.havePassword) {
		return firebase.auth().signInWithEmailAndPassword(this.currentUser.auth.email, password);
	}else{
		switch (this.currentUser.provider) {
		  case 2 : //facebook.com
			return Facebook.login(['email']);
		  case 3 : //google.com
			return GooglePlus.login({
				'webClientId': '******************************.apps.googleusercontent.com',
				'offline': true,
			});
		  default :
			console.log("Unknown provider number : " + this.currentUser.provider);
			return null;
		}
	}
  }

This app work with Firebase3.
And to i use this function like this :

  updateEmail(email, password): any {
	  return new Promise<void>((resolve, reject) => {
		  this.reconnectUser(password).then(
			  () => {
				// User re-authenticated.
				this.currentUser.auth.updateEmail(email).then(
					(succ) => {
						resolve(succ);
					}, (error) => {
						reject(error);
					});
			  }, (error) => {
				reject(error);
			});
		});
  }

I’m not sure this is the best way to do it, but it is working. If someone have something else i will be curious to take a look at other solutions.


#3

I’m building a similar solution, but it really sounds like a “workaround”, and not exactly the native “re-authenticate” feature I would like to implement.

For now, it will do though.

If anyone has a more native approach, I would gladly welcome it.
Until then, thanks @mvrc :slight_smile: