0

I'm using reqwest to authenticate users using google oauth. I have set the credentials correctly (client_id, secret, redirect_uris) but I still cannot exchange the code that I get from google to get the tokens.

let mut params = HashMap::new();
params.insert("client_id", &config.web.client_id);
params.insert("client_secret", &config.web.client_secret);
params.insert("grant_type", &grant_type);
params.insert("redirect_uri", &redirect_uri);
params.insert("code", code);

let client = reqwest::blocking::Client::new();
if let Ok(response) = client.post("https://oauth2.googleapis.com/token")
  .form(&params)
  .send() {
  println!("{:?}", response);
}

it always returns redirect_uri_mismatch. The redirect_uri for retrieving the code during authentication works but the redirect_uri for retrieving the access and refresh token does not. I have a similar webapp in php using the same redirect uris and it works. I just cannot make it work for rust.

I am using different redirect_uri when getting the authorization code from the https://accounts.google.com/o/oauth2/v2/auth endpoint and another redirect_uri when posting to https://oauth2.googleapis.com/token to get the access and refresh token.

ferd tomale
  • 845
  • 7
  • 20
  • Does this answer your question? [Google OAuth 2 authorization - Error: redirect\_uri\_mismatch](https://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch) – eggyal Jun 05 '21 at 08:09
  • no. I have read that thread and I have done changed the redirect uri several times just in case. I have also tried waiting 2 days to see if it was just a time related issue but to no avail. really stumped. – ferd tomale Jun 05 '21 at 12:56
  • It turns out that I cannot use different redirect_uri when getting ```https://accounts.google.com/o/oauth2/v2/auth``` to get the authorization code and posting to ```https://oauth2.googleapis.com/token``` to get the access and refresh token. – ferd tomale Jun 06 '21 at 10:21

1 Answers1

0

It turns out I cannot use a different redirect uri when retrieving the authorization code and retrieving the access token.

ferd tomale
  • 845
  • 7
  • 20