Skip to content

Commit

Permalink
fix(refresh): use correct URL for refresh flow
Browse files Browse the repository at this point in the history
This also allowed us to simplify the API once again.
  • Loading branch information
Byron committed Apr 23, 2015
1 parent 2481c75 commit 1ce4147
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "yup-oauth2"
version = "0.3.5"
version = "0.3.6"
authors = ["Sebastian Thiel <[email protected]>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
Expand Down
3 changes: 1 addition & 2 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ impl<D, S, C> GetToken for Authenticator<D, S, C>
match *rf.refresh_token(self.flow_type,
&self.secret.client_id,
&self.secret.client_secret,
&t.refresh_token,
scopes.iter()) {
&t.refresh_token) {
RefreshResult::Error(ref err) => {
match self.delegate.connection_error(err) {
Retry::Abort|Retry::Skip =>
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
//! let mut f = RefreshFlow::new(hyper::Client::new());
//! let new_token = match *f.refresh_token(FlowType::Device,
//! "my_client_id", "my_secret",
//! "my_refresh_token",
//! &["https://scope.url"]) {
//! "my_refresh_token") {
//! RefreshResult::Success(ref t) => t,
//! _ => panic!("bad luck ;)")
//! };
Expand Down
29 changes: 10 additions & 19 deletions src/refresh.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use common::{FlowType, JsonError};
use device::GOOGLE_TOKEN_URL;

use chrono::UTC;
use hyper;
use hyper::header::ContentType;
use rustc_serialize::json;
use url::form_urlencoded;
use super::Token;
use itertools::Itertools;
use std::borrow::BorrowMut;
use std::io::Read;
use std::iter::IntoIterator;

/// Implements the [Outh2 Refresh Token Flow](https://developers.google.com/youtube/v3/guides/authentication#devices).
///
Expand Down Expand Up @@ -56,15 +55,12 @@ impl<C> RefreshFlow<C>
///
/// # Examples
/// Please see the crate landing page for an example.
pub fn refresh_token<'b, I, T>( &mut self,
flow_type: FlowType,
client_id: &str,
client_secret: &str,
refresh_token: &str,
scopes: I)
-> &RefreshResult
where T: AsRef<str> + Ord,
I: IntoIterator<Item=&'b T> {
pub fn refresh_token(&mut self,
flow_type: FlowType,
client_id: &str,
client_secret: &str,
refresh_token: &str) -> &RefreshResult {
let _ = flow_type;
if let RefreshResult::Success(_) = self.result {
return &self.result;
}
Expand All @@ -73,16 +69,11 @@ impl<C> RefreshFlow<C>
[("client_id", client_id),
("client_secret", client_secret),
("refresh_token", refresh_token),
("grant_type", "refresh_token"),
("scope", scopes.into_iter()
.map(|s| s.as_ref())
.intersperse(" ")
.collect::<String>()
.as_ref())]
("grant_type", "refresh_token")]
.iter().cloned());

let json_str =
match self.client.borrow_mut().post(flow_type.as_ref())
match self.client.borrow_mut().post(GOOGLE_TOKEN_URL)
.header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
.body(&*req)
.send() {
Expand Down Expand Up @@ -153,7 +144,7 @@ mod tests {


match *flow.refresh_token(FlowType::Device,
"bogus", "secret", "bogus_refresh_token", &["scope.url"]) {
"bogus", "secret", "bogus_refresh_token") {
RefreshResult::Success(ref t) => {
assert_eq!(t.access_token, "1/fFAGRNJru1FTz70BzhT3Zg");
assert!(!t.expired());
Expand Down

0 comments on commit 1ce4147

Please sign in to comment.