mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-10 12:49:28 +01:00
fix(refresh): use correct URL for refresh flow
This also allowed us to simplify the API once again.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
|
||||
name = "yup-oauth2"
|
||||
version = "0.3.5"
|
||||
version = "0.3.6"
|
||||
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
|
||||
repository = "https://github.com/Byron/yup-oauth2"
|
||||
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
|
||||
|
||||
@@ -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 =>
|
||||
|
||||
@@ -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 ;)")
|
||||
//! };
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use common::{FlowType, JsonError};
|
||||
use device::GOOGLE_TOKEN_URL;
|
||||
|
||||
use chrono::UTC;
|
||||
use hyper;
|
||||
@@ -6,10 +7,8 @@ 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).
|
||||
///
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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() {
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user