mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
use POST instead GET to init or refresh oauth2 tokens
This commit is contained in:
@@ -123,14 +123,37 @@ pub fn dc_get_oauth2_access_token(
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let mut token_url = replace_in_uri(&token_url, "$CLIENT_ID", oauth2.client_id);
|
|
||||||
token_url = replace_in_uri(&token_url, "$REDIRECT_URI", &redirect_uri);
|
// to allow easier specification of different configurations,
|
||||||
token_url = replace_in_uri(&token_url, "$CODE", code.as_ref());
|
// token_url is in GET-method-format, sth. as https://domain?param1=val1¶m2=val2 -
|
||||||
if let Some(ref token) = refresh_token {
|
// convert this to POST-format ...
|
||||||
token_url = replace_in_uri(&token_url, "$REFRESH_TOKEN", token);
|
let mut parts = token_url.splitn(2, '?');
|
||||||
|
let post_url = parts.next().unwrap_or_default();
|
||||||
|
let post_args = parts.next().unwrap_or_default();
|
||||||
|
let mut post_param = HashMap::new();
|
||||||
|
for key_value_pair in post_args.split('&') {
|
||||||
|
let mut parts = key_value_pair.splitn(2, '=');
|
||||||
|
let key = parts.next().unwrap_or_default();
|
||||||
|
let mut value = parts.next().unwrap_or_default();
|
||||||
|
|
||||||
|
if value == "$CLIENT_ID" {
|
||||||
|
value = oauth2.client_id;
|
||||||
|
} else if value == "$REDIRECT_URI" {
|
||||||
|
value = &redirect_uri;
|
||||||
|
} else if value == "$CODE" {
|
||||||
|
value = code.as_ref();
|
||||||
|
} else if value == "$REFRESH_TOKEN" && refresh_token.is_some() {
|
||||||
|
value = refresh_token.as_ref().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = reqwest::Client::new().post(&token_url).send();
|
post_param.insert(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... and POST
|
||||||
|
let response = reqwest::Client::new()
|
||||||
|
.post(post_url)
|
||||||
|
.form(&post_param)
|
||||||
|
.send();
|
||||||
if response.is_err() {
|
if response.is_err() {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
|
|||||||
Reference in New Issue
Block a user