Installed Application Redirect uri mismatch on live site which is working on localhost

I have developed an google analytics plugin , Getting URI mismatch error on authentication . It is working well on localhost , but when I installed it on a site, It displays this error.

My redirect uri that is created on browser address bar during authentication and

Read More

showing error uri mismatch

https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=auto&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly&response_type=code&redirect_uri=http%3A%2F%2Fapp.mysite.com%2Fwp-admin%2Fadmin.php%3Fpage%3Danalytica-admin-settings%2F&client_id=id.apps.googleusercontent.com&include_granted_scopes=true&hl=en&from_login=1&as=6532dbe8b26fcb0f&authuser=3

and on localhost something like this and it is working

https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=auto&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly&response_type=code&redirect_uri=http%3A%2F%2Fhttp://localhost/test/%2Fwp-admin%2Fadmin.php%3Fpage%3Danalytica-admin-settings%2F&client_id=id.apps.googleusercontent.com&include_granted_scopes=true&hl=en&from_login=1&as=6532dbe8b26fcb0f&authuser=3

The only difference in bot the url is the redirect URI, one is one localhost and the other one is live .

With ” urn:ietf:wg:oauth:2.0:oob” as redirect URI with a popup for authentication is working fine on both local site on live site. But the URL I have mentioned is working on localhost , but not working on live site.

on documentation choosing a redirect uri for insatlledApp

**http://localhost[:port]

This value signals to the Google Authorization Server that the authorization code should be returned as a query string parameter to the web server on the client. To receive the authorization code using this URL, your application must be listening on the local web server. This is possible on many, but not all, platforms. If your platform supports it, this is the recommended mechanism for obtaining the authorization code.
** Does it mean we can use it only on localhost ? but I have used a number of plugins which are using redirecturi for authorization .

Can anyone give me a solution for this or any idea, how I can achieve this.

This is how I am setting the redirect uri here.

$client->setRedirectUri( site_url() . '/wp-admin/admin.php?page=analytica-admin-settings');

Installed app does not need redirect uri to be set on console.
Check screenshot
enter image description here

Related posts