Merge pull request #30 from edelangh/update_reqwest
Update reqwest to 0.9.5
This commit is contained in:
commit
f26dd834f5
|
@ -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"
|
||||
|
|
|
@ -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, 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<P: Provider> Client<P> {
|
|||
fn post_token(
|
||||
&self,
|
||||
http_client: &reqwest::Client,
|
||||
mut body: Serializer<String>
|
||||
mut body: Serializer<String>,
|
||||
) -> Result<Value, ClientError> {
|
||||
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()?;
|
||||
|
||||
|
|
|
@ -112,14 +112,14 @@
|
|||
//! # extern crate reqwest;
|
||||
//! # use inth_oauth2::Client;
|
||||
//! # use inth_oauth2::provider::google::Installed;
|
||||
//! use reqwest::header::Authorization;
|
||||
//! use inth_oauth2::Token;
|
||||
//!
|
||||
//! # fn main() {
|
||||
//! # let oauth_client = Client::new(Installed, String::new(), String::new(), None);
|
||||
//! # let http = reqwest::Client::new();
|
||||
//! # let token = oauth_client.request_token(&http, "").unwrap();
|
||||
//! let request = http.get("https://example.com/resource")
|
||||
//! .header(Into::<Authorization<_>>::into(&token))
|
||||
//! .bearer_auth(token.access_token())
|
||||
//! .build();
|
||||
//! # }
|
||||
//! ```
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use reqwest::header;
|
||||
use serde_json::Value;
|
||||
|
||||
use client::response::{FromResponse, ParseError};
|
||||
|
@ -15,14 +14,14 @@ pub struct Bearer<L: Lifetime> {
|
|||
}
|
||||
|
||||
impl<L: Lifetime> Token<L> for Bearer<L> {
|
||||
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<header::Authorization<header::Bearer>> for &'a Bearer<L> {
|
||||
fn into(self) -> header::Authorization<header::Bearer> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use url::Url;
|
|||
|
||||
fn assert_get_uri_ok(uri: Url) {
|
||||
let response = reqwest::get(uri).unwrap();
|
||||
assert_eq!(reqwest::StatusCode::Ok, response.status());
|
||||
assert_eq!(reqwest::StatusCode::OK, response.status());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue