0

I would like to create google authentication but can't find an error: I have a code below:

$client_id = 'xxxxxxx-4bsrudsadhna5817fddlhmf02ihgrcr0.apps.googleusercontent.com'; 
$client_secret = 'xxxxxxxxxxxxxxxxxx';
$redirect_uri = 'http://`localhost`/joomla/index.php?option=com_component&view=quest&task=signup'; 
$url = 'https://accounts.google.com/o/oauth2/auth';
$params = array(
'redirect_uri'      => $redirect_uri,
'response_type'     => 'code',
'client_id'         => $client_id,
'scope'             => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
);  

$this->google_auth_link = $url . '?' . urldecode(http_build_query($params));

echo '<a href="'.$this->google_auth_link.'">Login using Google +</a>';

But this returns me:

400 - That’s an error.
Error: redirect_uri_mismatch

The redirect URI in the request: http://localhost/joomla/index.php?option=com_component did not match a registered redirect URI

P.S Seems to be this part of URI has been dropped: &view=quest&task=signup

Thanks!

3
  • Why are you using urldecode here? That makes absolutely no sense.
    – CBroe
    Sep 9, 2014 at 7:48
  • This is very odd but without urldecode this code works! Why?
    – XTRUST.ORG
    Sep 9, 2014 at 7:52
  • Because only that way the parameters you are passing are URL-encoded properly, which http_build_query takes care of - and by deliberately reverting that you are messing it up.
    – CBroe
    Sep 9, 2014 at 7:55

1 Answer 1

0

You can't use the backtick operator inside single quotes. The 3rd line should be

$redirect_uri = 'http://'.`localhost`.'/joomla/index.php?option=com_component&view=quest&task=signup'; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.