diff --git a/Cargo.toml b/Cargo.toml index 308fd5b..7c9821e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "0.2.1" +version = "0.2.2" authors = ["Sebastian Thiel "] repository = "https://github.com/Byron/yup-oauth2" description = "A partial oauth2 implementation, providing the 'device' authorization flow" @@ -20,5 +20,5 @@ rustc-serialize = "*" [dev-dependencies] getopts = "*" -yup-hyper-mock = "*" +yup-hyper-mock = ">= 0.1.3" open = "*" diff --git a/src/device.rs b/src/device.rs index 6a42bd2..6ea6fc0 100644 --- a/src/device.rs +++ b/src/device.rs @@ -10,6 +10,7 @@ use rustc_serialize::json; use chrono::{DateTime,UTC}; use std::borrow::BorrowMut; use std::marker::PhantomData; +use std::io::Read; use common::{Token, FlowType, Flow}; @@ -192,7 +193,8 @@ impl DeviceFlow // json::Json::from_reader(&mut res) // .ok() // .expect("decode must work!"))).unwrap(); - let json_str = String::from_utf8(res.read_to_end().unwrap()).unwrap(); + let mut json_str = String::new(); + res.read_to_string(&mut json_str).ok().expect("string decode must work"); // check for error match json::decode::(&json_str) { @@ -267,7 +269,9 @@ impl DeviceFlow return PollResult::Error(err); } Ok(mut res) => { - String::from_utf8(res.read_to_end().unwrap()).unwrap() + let mut json_str = String::new(); + res.read_to_string(&mut json_str).ok().expect("string decode must work"); + json_str } }; diff --git a/src/lib.rs b/src/lib.rs index 92eb24f..645e65f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(old_io, std_misc, core, hash)] +#![feature(io, old_io, std_misc, core, hash)] //! 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 //! for [refreshing tokens](https://developers.google.com/youtube/v3/guides/authentication#devices) diff --git a/src/refresh.rs b/src/refresh.rs index 4eef64c..5b400ca 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -8,6 +8,7 @@ use url::form_urlencoded; use super::Token; use std::borrow::BorrowMut; use std::marker::PhantomData; +use std::io::Read; /// Implements the [Outh2 Refresh Token Flow](https://developers.google.com/youtube/v3/guides/authentication#devices). /// @@ -82,7 +83,9 @@ impl RefreshFlow return &self.result; } Ok(mut res) => { - String::from_utf8(res.read_to_end().unwrap()).unwrap() + let mut json_str = String::new(); + res.read_to_string(&mut json_str).ok().expect("string decode must work"); + json_str } };