make oauth2.get_addr work

oauth2.get_addr is used for gmail-oauth2
to retrieve the address really authorized in the oauth2 process.
This commit is contained in:
B. Petersen
2019-10-16 00:57:58 +02:00
parent 120524ae00
commit cde2c9137f
2 changed files with 5 additions and 2 deletions

View File

@@ -297,7 +297,7 @@ impl Oauth2 {
return None;
}
let parsed: reqwest::Result<HashMap<String, String>> = response.json();
let parsed: reqwest::Result<HashMap<String, serde_json::Value>> = response.json();
if parsed.is_err() {
warn!(
context,
@@ -306,11 +306,13 @@ impl Oauth2 {
return None;
}
if let Ok(response) = parsed {
// serde_json::Value.as_str() removes the quotes of json-strings
let addr = response.get("email");
if addr.is_none() {
warn!(context, "E-mail missing in userinfo.");
return None;
}
let addr = addr.unwrap().as_str();
addr.map(|addr| addr.to_string())
} else {
warn!(context, "Failed to parse userinfo.");