Google OAuth2 redirect_uri_mismatch when your url contains "&"

929 views Asked by At

I am using the PHP HybridAuth library and integrating oauth2 support, all providers such as Yahoo, MSN and Facebook works, except Google, showing

The redirect URI in the request: 
https://www.example.com/auth?action=callback&hauth.done=Google did not match a registered redirect URI.

My redirect url is : https://www.example.com/auth?action=callback&hauth.done=Google, I've added both urls to see if I can workaround for their non sense escape limitation, e.g.

https://www.example.com/auth?action=callback&hauth.done=Google
https://www.example.com/auth?action=callback&hauth.done=Google 

Still no luck...Any idea?

2

There are 2 answers

0
Lucas NN On

You need use the PHP urlencode function.

urlencode — URL-encodes string
(PHP 4, PHP 5)

string urlencode ( string $str )

This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.

Example:

$encoded_url = urlencode("https://www.example.com/auth?action=callback&hauth.done=Google");

More informations:

HTML URL Encoding Reference

http://www.w3schools.com/tags/ref_urlencode.asp

PHP urlencode

http://php.net/manual/en/function.urlencode.php

0
Sudhir Bastakoti On

just an assumption, try urlencode()'ing the url,

$url = "https://www.example.com/auth?action=callback" . urlencode("&hauth.done=Google");