I would like to add facebook login option to my website, following this tutorial. I did everything as it is in the tutorial, but I still get this error:
OAuthException: redirect_uri isn't an absolute URI
How is it possible to solve it?
This urls are generated by the facebookOAuthProvider
. The website is not on localhost. It runs on a webserver, with https.
This is the relevant code:
// redirect to Facebook
$facebookOAuthProvider = $this->get('app.facebook_provider');
$url = $facebookOAuthProvider->getAuthorizationUrl([
// these are actually the default scopes
'scopes' => ['public_profile', 'email'],
]);
return $this->redirect($url);
It redirects to this url:
https://www.facebook.com/v2.3/dialog/oauth?scopes[0]=public_profile&scopes[1]=email&state=...&scope=public_profile,email&response_type=code&approval_prompt=auto&redirect_uri=/connect/facebook-check&client_id=...
The redirect_uri
is indeed not an absolute url. But how is it possible to fix it?
Edit
If I add 'redirect_uri' => [$redir]
then the url looks like this:
https://www.facebook.com/v2.3/dialog/oauth?scopes%5B0%5D=public_profile&scopes%5B1%5D=email&scopes%5B2%5D=user_location&redirect_uri%5B0%5D=https%3A%2F%2Fexample.com%2Fconnect%2Ffacebook-check&state=...&scope=public_profile%2Cemail&response_type=code&approval_prompt=auto&client_id=...
I can see the absolute redirect_uri
in the generated url, but I still get this error, if I navigate to it
Redir is defined as:
$redir = $this->generateUrl('connect_facebook_check', array(), UrlGeneratorInterface::ABSOLUTE_URL);
Edit2
If I replace [$redir]
with $redir
then facebook redirects me correctly to /connect/facebook-check
with a code, but I get a OAuthException: redirect_uri isn't an absolute URI. Check RFC 3986
there.
I don't know where you got the example code, but certainly not from the linked tutorial.
Facebook authorization is based on the fact that you generate a link to FB, the user goes to the FB and authorizes himself, and then the FB server redirects it back to you (along with whether or not it is authorized).
FB does not guess where to redirect user after login. You need to give him a full path with http(s) and the server name (and if I remember correctly, it is also compatible with that saved in the FB app)
The attached tutorial requires writing a controller with 2 methods (output and return) and corresponding entries in the configuration.
If you use this, then see how you have configured the provider. What is in redirectUri
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With