I am trying to run the Oauth2 stack in our google development project, but I keep getting the error:
Error 400: redirect_uri_mismatch
In the console, I have defined these two "Authorized redirect URIs":
https://edit.<MY DOMAIN>/oauth2callback
https://<MY DOMAIN>/oauth2callback
(I added the second to try and get around the problem). The URL I'm going to for oauth is:
https://accounts.google.com/o/oauth2/v2/auth?response_type=code&
access_type=offline&
client_id=<MY CLIENT ID>.apps.googleusercontent.com&
redirect_uri=https%3A%2F%2Fedit.<MY DOMAIN>%2Foauth2callback&
state=host%3Dhttps%3A%2F%2Fwebhosts.<MY DOMAIN>%2F-%2FControlGoogleAnalytics%2Foauth2callback&
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.edit%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&
approval_prompt=force&
include_granted_scopes=true&
login_hint=<MY LOGIN HINT>
Which seems to be correct, but I am getting the uri mismatch error, even an hour or so after I added the Redirect URIs in the google cloud console. Is it just that I have to wait longer? Or did I miss something?
My PHP code at this point is dead simple. There is a form that lets me pass in a google account name that I have already created ([email protected]) so I can use it as a login hint, then:
$google_user_account_name = <validated account name string>;
$this->google_oauth_url = $createAuthUrl() . \
"&login_hint={$google_user_account_name}");
$this->redirect( $this->google_oauth_url );
The generated oauth_url at this point is:
https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=offline&client_id=<CLIENT ID>.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fedit.elite80-001.ihousedev.com%2Foauth2callback&state=host%3Dhttps%3A%2F%2Fwebhosts.elite80-001.ihousedev.com%2F-%2FControlGoogleAnalytics%2Foauth2callback&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.edit%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&approval_prompt=force&include_granted_scopes=true
The redirect URIs in the console include:
https://elite80-001.ihousedev.com
https://www.elite80-001.ihousedev.com
https://edit.elite80-001.ihousedev.com
https://edit.elite80-001.ihousedev.com/oauth2callback
I think that the first 3 are unnecessary, but I was trying everything I could think of...
Well, I found that the problem was that my database had been altered, and the clientId was incorrect. Don't know why I didn't catch that sooner. I identified the correct Oauth client and downloaded the json file, installed it, and now I am onto the next problem. Thanks all.