Skip to content

Commit

Permalink
fix(version-up): v0.3.3
Browse files Browse the repository at this point in the history
* hyper adjustments to deal with Client without type parameter
* adjust to changed crate name conventions, '-' are converted to '_'

Fixes #3
  • Loading branch information
Byron committed Apr 8, 2015
1 parent fec6113 commit 0222a19
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 38 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.2"
version = "0.3.3"
authors = ["Sebastian Thiel <[email protected]>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
Expand Down
4 changes: 2 additions & 2 deletions examples/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(collections, old_io, std_misc, exit_status)]
#![allow(deprecated)]
extern crate "yup-oauth2" as oauth2;
extern crate "yup-hyper-mock" as mock;
extern crate yup_oauth2 as oauth2;
extern crate yup_hyper_mock as mock;
extern crate hyper;
extern crate chrono;
extern crate getopts;
Expand Down
17 changes: 6 additions & 11 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use itertools::Itertools;
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};
Expand All @@ -21,17 +20,15 @@ pub const GOOGLE_TOKEN_URL: &'static str = "https://accounts.google.com/o/oauth2
/// It operates in two steps:
/// * obtain a code to show to the user
/// * (repeatedly) poll for the user to authenticate your application
pub struct DeviceFlow<C, NC> {
pub struct DeviceFlow<C> {
client: C,
device_code: String,
state: PollResult,
secret: String,
id: String,

_m: PhantomData<NC>,
}

impl<C, NC> Flow for DeviceFlow<C, NC> {
impl<C> Flow for DeviceFlow<C> {
fn type_id() -> FlowType {
FlowType::Device
}
Expand Down Expand Up @@ -103,28 +100,26 @@ impl Default for PollResult {
}
}

impl<C, NC> DeviceFlow<C, NC>
where C: BorrowMut<hyper::Client<NC>>,
NC: hyper::net::NetworkConnector {
impl<C> DeviceFlow<C>
where C: BorrowMut<hyper::Client> {

/// # Examples
/// ```test_harness
/// extern crate hyper;
/// extern crate "yup-oauth2" as oauth2;
/// extern crate yup_oauth2 as oauth2;
/// use oauth2::DeviceFlow;
///
/// # #[test] fn new() {
/// let mut f = DeviceFlow::new(hyper::Client::new());
/// # }
/// ```
pub fn new(client: C) -> DeviceFlow<C, NC> {
pub fn new(client: C) -> DeviceFlow<C> {
DeviceFlow {
client: client,
device_code: Default::default(),
secret: Default::default(),
id: Default::default(),
state: Default::default(),
_m: PhantomData,
}
}

Expand Down
18 changes: 6 additions & 12 deletions src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::iter::IntoIterator;
use std::borrow::BorrowMut;
use std::marker::PhantomData;
use std::collections::HashMap;
use std::hash::{SipHasher, Hash, Hasher};
use std::old_io::timer::sleep;
Expand Down Expand Up @@ -70,14 +69,12 @@ impl TokenStorage for MemoryStorage {
///
/// # Usage
/// Please have a look at the library's landing page.
pub struct Authenticator<D, S, C, NC> {
pub struct Authenticator<D, S, C> {
flow_type: FlowType,
delegate: D,
storage: S,
client: C,
secret: ApplicationSecret,

_m: PhantomData<NC>
}

/// A provider for authorization tokens, yielding tokens valid for a given scope.
Expand All @@ -91,11 +88,10 @@ pub trait GetToken {
fn api_key(&mut self) -> Option<String>;
}

impl<D, S, C, NC> Authenticator<D, S, C, NC>
impl<D, S, C> Authenticator<D, S, C>
where D: AuthenticatorDelegate,
S: TokenStorage,
NC: hyper::net::NetworkConnector,
C: BorrowMut<hyper::Client<NC>> {
C: BorrowMut<hyper::Client> {


/// Returns a new `Authenticator` instance
Expand All @@ -113,14 +109,13 @@ impl<D, S, C, NC> Authenticator<D, S, C, NC>
/// [dev-con]: https://console.developers.google.com
pub fn new(secret: &ApplicationSecret,
delegate: D, client: C, storage: S, flow_type: Option<FlowType>)
-> Authenticator<D, S, C, NC> {
-> Authenticator<D, S, C> {
Authenticator {
flow_type: flow_type.unwrap_or(FlowType::Device),
delegate: delegate,
storage: storage,
client: client,
secret: secret.clone(),
_m: PhantomData
}
}

Expand Down Expand Up @@ -181,11 +176,10 @@ impl<D, S, C, NC> Authenticator<D, S, C, NC>
}
}

impl<D, S, C, NC> GetToken for Authenticator<D, S, C, NC>
impl<D, S, C> GetToken for Authenticator<D, S, C>
where D: AuthenticatorDelegate,
S: TokenStorage,
NC: hyper::net::NetworkConnector,
C: BorrowMut<hyper::Client<NC>> {
C: BorrowMut<hyper::Client> {

/// Blocks until a token was retrieved from storage, from the server, or until the delegate
/// decided to abort the attempt, or the user decided not to authorize the application.
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
//!
//! ```test_harness,no_run
//! extern crate hyper;
//! extern crate "yup-oauth2" as oauth2;
//! extern crate "rustc-serialize" as rustc_serialize;
//! extern crate yup_oauth2 as oauth2;
//! extern crate rustc_serialize;
//!
//! use oauth2::{Authenticator, DefaultAuthenticatorDelegate, PollInformation, ConsoleApplicationSecret, MemoryStorage, GetToken};
//! use rustc_serialize::json;
Expand Down Expand Up @@ -47,7 +47,7 @@
//!
//! ```test_harness,no_run
//! extern crate hyper;
//! extern crate "yup-oauth2" as oauth2;
//! extern crate yup_oauth2 as oauth2;
//! use oauth2::{RefreshFlow, FlowType, RefreshResult};
//!
//! # #[test] fn refresh() {
Expand Down
13 changes: 4 additions & 9 deletions src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ use rustc_serialize::json;
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).
///
/// Refresh an expired access token, as obtained by any other authentication flow.
/// This flow is useful when your `Token` is expired and allows to obtain a new
/// and valid access token.
pub struct RefreshFlow<C, NC> {
pub struct RefreshFlow<C> {
client: C,
result: RefreshResult,

_m: PhantomData<NC>,
}


Expand All @@ -33,15 +30,13 @@ pub enum RefreshResult {
Success(Token),
}

impl<C, NC> RefreshFlow<C, NC>
where NC: hyper::net::NetworkConnector,
C: BorrowMut<hyper::Client<NC>> {
impl<C> RefreshFlow<C>
where C: BorrowMut<hyper::Client> {

pub fn new(client: C) -> RefreshFlow<C, NC> {
pub fn new(client: C) -> RefreshFlow<C> {
RefreshFlow {
client: client,
result: RefreshResult::Error(hyper::HttpError::HttpStatusError),
_m: PhantomData,
}
}

Expand Down

0 comments on commit 0222a19

Please sign in to comment.