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(¶ms)
.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.