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.
UrlGeneratorInterface::ABSOLUTE_URL
into the URL generation process somehow, otherwise it will create relative URLs by default when the protocol, domain and port match. symfony.com/doc/current/routing.html#generating-absolute-urls – Elnoraelnore'redirect_uri' => [$redir]
, then I can see the absolute redirect_uri in the generated url, but I still get this error, if I navigate to it – Heer...
– Heer