Factor out auth_header and accept_header
This commit is contained in:
parent
91dd81690d
commit
6da1277507
|
@ -152,16 +152,17 @@ impl Client {
|
||||||
Ok(uri.serialize())
|
Ok(uri.serialize())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requests an access token using an authorization code.
|
fn auth_header(&self) -> header::Authorization<header::Basic> {
|
||||||
pub fn request_token(&self, code: &str) -> Result<Token> {
|
header::Authorization(
|
||||||
let auth_header = header::Authorization(
|
|
||||||
header::Basic {
|
header::Basic {
|
||||||
username: self.client_id.clone(),
|
username: self.client_id.clone(),
|
||||||
password: Some(self.client_secret.clone()),
|
password: Some(self.client_secret.clone()),
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let accept_header = header::Accept(vec![
|
fn accept_header(&self) -> header::Accept {
|
||||||
|
header::Accept(vec![
|
||||||
header::qitem(
|
header::qitem(
|
||||||
mime::Mime(
|
mime::Mime(
|
||||||
mime::TopLevel::Application,
|
mime::TopLevel::Application,
|
||||||
|
@ -169,8 +170,11 @@ impl Client {
|
||||||
vec![]
|
vec![]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
]);
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Requests an access token using an authorization code.
|
||||||
|
pub fn request_token(&self, code: &str) -> Result<Token> {
|
||||||
let mut body_pairs = vec![
|
let mut body_pairs = vec![
|
||||||
("grant_type", "authorization_code"),
|
("grant_type", "authorization_code"),
|
||||||
("code", code),
|
("code", code),
|
||||||
|
@ -182,8 +186,8 @@ impl Client {
|
||||||
let body_str = form_urlencoded::serialize(body_pairs);
|
let body_str = form_urlencoded::serialize(body_pairs);
|
||||||
|
|
||||||
let request = self.http_client.post(&self.token_uri)
|
let request = self.http_client.post(&self.token_uri)
|
||||||
.header(auth_header)
|
.header(self.auth_header())
|
||||||
.header(accept_header)
|
.header(self.accept_header())
|
||||||
.header(header::ContentType::form_url_encoded())
|
.header(header::ContentType::form_url_encoded())
|
||||||
.body(&body_str);
|
.body(&body_str);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue