From ff8b0aea71b9d01926ba9a18d8e239d48284d297 Mon Sep 17 00:00:00 2001 From: edelangh Date: Fri, 12 Oct 2018 16:25:31 +0200 Subject: [PATCH] Update reqwest to 0.9.5 Have remove impl Into> for Bearer because Authorization does not exist any more --- Cargo.toml | 2 +- src/client/mod.rs | 27 ++++++++++----------------- src/token/bearer.rs | 17 ++++++++--------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fd1e9de..6dd8035 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ serde = "1.0.8" serde_derive = "1.0.5" serde_json = "1.0.2" url = "1.1.0" -reqwest = "0.8.0" +reqwest = "0.9.2" diff --git a/src/client/mod.rs b/src/client/mod.rs index d0f1a71..814a2d2 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -5,15 +5,16 @@ mod error; pub mod response; pub use self::error::ClientError; -use reqwest::{self, header, mime}; +use reqwest; +use reqwest::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE}; use serde_json::{self, Value}; -use url::Url; use url::form_urlencoded::Serializer; +use url::Url; use client::response::FromResponse; use error::OAuth2Error; use provider::Provider; -use token::{Token, Lifetime, Refresh}; +use token::{Lifetime, Refresh, Token}; /// OAuth 2.0 client. #[derive(Debug, Clone, PartialEq, Eq)] @@ -110,28 +111,20 @@ impl Client

{ fn post_token( &self, http_client: &reqwest::Client, - mut body: Serializer + mut body: Serializer, ) -> Result { if self.provider.credentials_in_body() { body.append_pair("client_id", &self.client_id); body.append_pair("client_secret", &self.client_secret); } - let auth_header = header::Authorization( - header::Basic { - username: self.client_id.clone(), - password: Some(self.client_secret.clone()), - } - ); - let accept_header = header::Accept(vec![ - header::qitem(mime::APPLICATION_JSON), - ]); let body = body.finish(); - let mut response = http_client.post(self.provider.token_uri().clone()) - .header(auth_header) - .header(accept_header) - .header(header::ContentType::form_url_encoded()) + let mut response = http_client + .post(self.provider.token_uri().clone()) + .basic_auth(&self.client_id, Some(&self.client_secret)) + .header(ACCEPT, "application/json") + .header(CONTENT_TYPE, "application/x-www-form-urlencoded") .body(body) .send()?; diff --git a/src/token/bearer.rs b/src/token/bearer.rs index 3f7f1f0..9478b94 100644 --- a/src/token/bearer.rs +++ b/src/token/bearer.rs @@ -1,4 +1,3 @@ -use reqwest::header; use serde_json::Value; use client::response::{FromResponse, ParseError}; @@ -15,14 +14,14 @@ pub struct Bearer { } impl Token for Bearer { - fn access_token(&self) -> &str { &self.access_token } - fn scope(&self) -> Option<&str> { self.scope.as_ref().map(|s| &s[..]) } - fn lifetime(&self) -> &L { &self.lifetime } -} - -impl<'a, L: Lifetime> Into> for &'a Bearer { - fn into(self) -> header::Authorization { - header::Authorization(header::Bearer { token: self.access_token.clone() }) + fn access_token(&self) -> &str { + &self.access_token + } + fn scope(&self) -> Option<&str> { + self.scope.as_ref().map(|s| &s[..]) + } + fn lifetime(&self) -> &L { + &self.lifetime } }