Reputation: 147
I am trying to use facebook oAuth for my users to login/register to my website. For this, i require user's email address
Facebook oAuth dialog has option to provide / not provide email but even if the user's doesn't provide their email, I cannot re-request authorization from facebook again as it considers the user as logged in and simply redirects to call back url.
I am using Laravel and Socialite package.
Any solutions??
Upvotes: 2
Views: 443
Reputation: 1723
Socialite allows you to get user information directly after the successful authorization by using
$user = Socialite::driver('facebook')->user();
$user->email;
I would expect $user->email
to contain the users email address if he accepted to share her with the app and to be empty if the user denied the email address sharing.
And if $user->email
is empty throw an error and ask the user to re-authorize. If it's not working you could try to de-authroize the user, a guide can be found here.
A convenient way to avoid any issues is to display a warning that the user should allow email sharing if he wants to log in with Facebook.
Upvotes: 2