SammyK / LaravelFacebookSdk

Fully unit tested Facebook SDK v5 integration for Laravel & Lumen
MIT License
693 stars 201 forks source link

Get access token in facebook tab #150

Closed JCarlosR closed 7 years ago

JCarlosR commented 7 years ago

I have implemented the login via redirect without problems. That works great with the next steps:

I have other route specially for the facebook tab. If the user have logged in before, there aren't problems. But if the user never have been logged into the app, the token is null when I use: $fb->getPageTabHelper()->getAccessToken();

At this point how I can request the user to accept the permissions? (The user is authenticated in facebook and see the facebook tab page).

SammyK commented 7 years ago

Hey @JCarlosR! If the user has already authorized your app but has denied a specific permission, the only way to ask for the permission again is with a rerequest url. Otherwise if they are authenticated with your app but were never presented the permission, a normal login link will work.

You can also check the /me/permissions edge on the User node to see what permissions the user has approved.

I hope that helps! :)

JCarlosR commented 7 years ago

@SammyK Thanks for your help. I perform a redirect in my controller using the following lines:

$callbackUrl = url('/facebook/callback?promotion='.$promotion->id, [], env('REDIRECT_HTTPS'));
$loginLink = $fb->getRedirectLoginHelper()->getLoginUrl($callbackUrl, ['email', 'user_location', 'user_likes']);

$htmlResponse = "<script>" .
  "window.top.location = '$loginLink';" .
   "</script>";
return $htmlResponse;

But after the user grants the permissions, an empty page shows the next message:

"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request"

I have added a GET parameter in my callbackUrl because this param exists in the previous page and I don't want to lose its value.