diff --git a/Cargo.toml b/Cargo.toml index 79b1c2524..b10b455f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "0.3.3" +version = "0.3.4" authors = ["Sebastian Thiel "] repository = "https://github.com/Byron/yup-oauth2" description = "A partial oauth2 implementation, providing the 'device' authorization flow" diff --git a/src/common.rs b/src/common.rs index a0bf758bd..fc01caf37 100644 --- a/src/common.rs +++ b/src/common.rs @@ -16,8 +16,8 @@ pub enum TokenType { Bearer, } -impl Str for TokenType { - fn as_slice(&self) -> &'static str { +impl AsRef for TokenType { + fn as_ref(&self) -> &'static str { match *self { TokenType::Bearer => "Bearer" } @@ -50,7 +50,7 @@ impl hyper::header::Scheme for Scheme { } fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} {}", self.token_type.as_slice(), self.access_token) + write!(f, "{} {}", self.token_type.as_ref(), self.access_token) } } @@ -134,9 +134,9 @@ pub enum FlowType { Device, } -impl Str for FlowType { +impl AsRef for FlowType { /// Converts itself into a URL string - fn as_slice(&self) -> &'static str { + fn as_ref(&self) -> &'static str { match *self { FlowType::Device => "https://accounts.google.com/o/oauth2/device/code", } diff --git a/src/device.rs b/src/device.rs index 874d0a9e4..28800b3cc 100644 --- a/src/device.rs +++ b/src/device.rs @@ -141,7 +141,7 @@ impl DeviceFlow /// See test-cases in source code for a more complete example. pub fn request_code<'b, T, I>(&mut self, client_id: &str, client_secret: &str, scopes: I) -> RequestResult - where T: Str, + where T: AsRef, I: IntoIterator { if self.device_code.len() > 0 { panic!("Must not be called after we have obtained a token and have no error"); @@ -152,14 +152,14 @@ impl DeviceFlow let req = form_urlencoded::serialize( [("client_id", client_id), ("scope", scopes.into_iter() - .map(|s| s.as_slice()) + .map(|s| s.as_ref()) .intersperse(" ") .collect::() - .as_slice())].iter().cloned()); + .as_ref())].iter().cloned()); - match self.client.borrow_mut().post(FlowType::Device.as_slice()) + match self.client.borrow_mut().post(FlowType::Device.as_ref()) .header(ContentType("application/x-www-form-urlencoded".parse().unwrap())) - .body(req.as_slice()) + .body(&*req) .send() { Err(err) => { return RequestResult::Error(Rc::new(err)); @@ -250,7 +250,7 @@ impl DeviceFlow // We should be ready for a new request let req = form_urlencoded::serialize( - [("client_id", self.id.as_slice()), + [("client_id", &self.id[..]), ("client_secret", &self.secret), ("code", &self.device_code), ("grant_type", "http://oauth.net/grant_type/device/1.0")] @@ -259,7 +259,7 @@ impl DeviceFlow let json_str = match self.client.borrow_mut().post(GOOGLE_TOKEN_URL) .header(ContentType("application/x-www-form-urlencoded".parse().unwrap())) - .body(req.as_slice()) + .body(&*req) .send() { Err(err) => { return PollResult::Error(Rc::new(err)); @@ -280,7 +280,7 @@ impl DeviceFlow Err(_) => {}, // ignore, move on, it's not an error Ok(res) => { pi.server_message = res.error; - self.state = match pi.server_message.as_slice() { + self.state = match pi.server_message.as_ref() { "access_denied" => PollResult::AccessDenied, "authorization_pending" => PollResult::AuthorizationPending(pi), _ => panic!("server message '{}' not understood", pi.server_message), diff --git a/src/helper.rs b/src/helper.rs index ac900219d..d11a16279 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -2,7 +2,7 @@ use std::iter::IntoIterator; use std::borrow::BorrowMut; use std::collections::HashMap; use std::hash::{SipHasher, Hash, Hasher}; -use std::old_io::timer::sleep; +use std::thread::sleep; use std::cmp::min; use common::{Token, FlowType, ApplicationSecret}; @@ -82,7 +82,7 @@ pub struct Authenticator { /// if no user is involved. pub trait GetToken { fn token<'b, I, T>(&mut self, scopes: I) -> Option - where T: Str + Ord, + where T: AsRef + Ord, I: IntoIterator; fn api_key(&mut self) -> Option; @@ -186,11 +186,11 @@ impl GetToken for Authenticator /// In any failure case, the returned token will be None, otherwise it is guaranteed to be /// valid for the given scopes. fn token<'b, I, T>(&mut self, scopes: I) -> Option - where T: Str + Ord, + where T: AsRef + Ord, I: IntoIterator { let (scope_key, scopes) = { let mut sv: Vec<&str> = scopes.into_iter() - .map(|s|s.as_slice()) + .map(|s|s.as_ref()) .collect::>(); sv.sort(); let s = sv.connect(" "); diff --git a/src/lib.rs b/src/lib.rs index c996bb228..2d2976028 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(old_io, std_misc, core)] +#![feature(std_misc, thread_sleep)] #![allow(deprecated)] //! This library can be used to acquire oauth2.0 authentication for services. //! At the time of writing, only one way of doing so is implemented, the [device flow](https://developers.google.com/youtube/v3/guides/authentication#devices), along with a flow @@ -60,7 +60,6 @@ //! }; //! # } //! ``` - extern crate chrono; #[macro_use] diff --git a/src/refresh.rs b/src/refresh.rs index 2d5d3e4df..183ebe231 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -69,9 +69,9 @@ impl RefreshFlow .iter().cloned()); let json_str = - match self.client.borrow_mut().post(flow_type.as_slice()) + match self.client.borrow_mut().post(flow_type.as_ref()) .header(ContentType("application/x-www-form-urlencoded".parse().unwrap())) - .body(req.as_slice()) + .body(&*req) .send() { Err(err) => { self.result = RefreshResult::Error(err);