mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-01 09:00:04 +01:00
Tidy up some imports.
No more need to macro_use serde. Order the imports consistently (albeit somewhat arbitrary), starting with items from this crate, followed by std, followed by external crates.
This commit is contained in:
@@ -18,9 +18,8 @@ hyper = {version = "0.13.0-alpha.4", features = ["unstable-stream"]}
|
||||
hyper-rustls = "=0.18.0-alpha.2"
|
||||
log = "0.4"
|
||||
rustls = "0.16"
|
||||
serde = "1.0"
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
url = "1"
|
||||
futures-preview = "=0.3.0-alpha.19"
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
use hyper;
|
||||
use crate::error::{Error, PollError, RefreshError};
|
||||
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt;
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::error::{Error, PollError, RefreshError};
|
||||
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use std::time::Duration;
|
||||
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use futures::prelude::*;
|
||||
use tio::AsyncBufReadExt;
|
||||
use tokio::io as tio;
|
||||
|
||||
/// A utility type to indicate how operations DeviceFlowHelper operations should be retried
|
||||
pub enum Retry {
|
||||
@@ -150,6 +145,7 @@ async fn present_user_url(
|
||||
url: &str,
|
||||
need_code: bool,
|
||||
) -> Result<String, Box<dyn StdError + Send + Sync>> {
|
||||
use tokio::io::AsyncBufReadExt;
|
||||
if need_code {
|
||||
println!(
|
||||
"Please direct your browser to {}, follow the instructions and enter the \
|
||||
@@ -157,7 +153,7 @@ async fn present_user_url(
|
||||
url
|
||||
);
|
||||
let mut user_input = String::new();
|
||||
match tio::BufReader::new(tio::stdin())
|
||||
match tokio::io::BufReader::new(tokio::io::stdin())
|
||||
.read_line(&mut user_input)
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
use crate::authenticator_delegate::{DefaultFlowDelegate, FlowDelegate, PollInformation, Retry};
|
||||
use crate::error::{Error, JsonErrorOr, PollError};
|
||||
use crate::types::{ApplicationSecret, Token};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::time::Duration;
|
||||
|
||||
use ::log::error;
|
||||
use chrono::{DateTime, Utc};
|
||||
use futures::prelude::*;
|
||||
use hyper;
|
||||
use hyper::header;
|
||||
use serde_json as json;
|
||||
use serde::Deserialize;
|
||||
use url::form_urlencoded;
|
||||
|
||||
use crate::authenticator_delegate::{DefaultFlowDelegate, FlowDelegate, PollInformation, Retry};
|
||||
use crate::error::{Error, JsonErrorOr, PollError};
|
||||
use crate::types::{ApplicationSecret, Token};
|
||||
|
||||
pub const GOOGLE_DEVICE_CODE_URL: &str = "https://accounts.google.com/o/oauth2/device/code";
|
||||
|
||||
// https://developers.google.com/identity/protocols/OAuth2ForDevices#step-4:-poll-googles-authorization-server
|
||||
@@ -162,7 +161,8 @@ impl DeviceFlow {
|
||||
}
|
||||
|
||||
let json_bytes = resp.into_body().try_concat().await?;
|
||||
let decoded: JsonData = json::from_slice::<JsonErrorOr<_>>(&json_bytes)?.into_result()?;
|
||||
let decoded: JsonData =
|
||||
serde_json::from_slice::<JsonErrorOr<_>>(&json_bytes)?.into_result()?;
|
||||
let expires_in = decoded.expires_in.unwrap_or(60 * 60);
|
||||
let pi = PollInformation {
|
||||
user_code: decoded.user_code,
|
||||
@@ -235,7 +235,7 @@ impl DeviceFlow {
|
||||
error: String,
|
||||
}
|
||||
|
||||
match json::from_slice::<JsonError>(&body) {
|
||||
match serde_json::from_slice::<JsonError>(&body) {
|
||||
Err(_) => {} // ignore, move on, it's not an error
|
||||
Ok(res) => {
|
||||
match res.error.as_ref() {
|
||||
@@ -255,7 +255,7 @@ impl DeviceFlow {
|
||||
}
|
||||
|
||||
// yes, we expect that !
|
||||
let mut t: Token = json::from_slice(&body).unwrap();
|
||||
let mut t: Token = serde_json::from_slice(&body).unwrap();
|
||||
t.set_expiry_absolute();
|
||||
|
||||
Ok(Some(t))
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::fmt;
|
||||
use std::io;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub(crate) struct JsonError {
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
//! Helper functions allowing you to avoid writing boilerplate code for common operations, such as
|
||||
//! parsing JSON or reading files.
|
||||
|
||||
// Copyright (c) 2016 Google Inc (lewinb@google.com).
|
||||
//
|
||||
// Refer to the project root for licensing information.
|
||||
|
||||
use serde_json;
|
||||
use crate::service_account::ServiceAccountKey;
|
||||
use crate::types::{ApplicationSecret, ConsoleApplicationSecret};
|
||||
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::service_account::ServiceAccountKey;
|
||||
use crate::types::{ApplicationSecret, ConsoleApplicationSecret};
|
||||
|
||||
/// Read an application secret from a file.
|
||||
pub fn read_application_secret<P: AsRef<Path>>(path: P) -> io::Result<ApplicationSecret> {
|
||||
parse_application_secret(std::fs::read_to_string(path)?)
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
//
|
||||
// Refer to the project root for licensing information.
|
||||
//
|
||||
use crate::authenticator_delegate::{DefaultFlowDelegate, FlowDelegate};
|
||||
use crate::error::{Error, JsonErrorOr};
|
||||
use crate::types::{ApplicationSecret, Token};
|
||||
|
||||
use std::convert::AsRef;
|
||||
use std::future::Future;
|
||||
use std::net::SocketAddr;
|
||||
@@ -10,16 +14,12 @@ use std::sync::{Arc, Mutex};
|
||||
|
||||
use futures::future::FutureExt;
|
||||
use futures_util::try_stream::TryStreamExt;
|
||||
use hyper;
|
||||
use hyper::header;
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::oneshot;
|
||||
use url::form_urlencoded;
|
||||
use url::percent_encoding::{percent_encode, QUERY_ENCODE_SET};
|
||||
|
||||
use crate::authenticator_delegate::{DefaultFlowDelegate, FlowDelegate};
|
||||
use crate::error::{Error, JsonErrorOr};
|
||||
use crate::types::{ApplicationSecret, Token};
|
||||
|
||||
const OOB_REDIRECT_URI: &str = "urn:ietf:wg:oauth:2.0:oob";
|
||||
|
||||
/// Assembles a URL to request an authorization token (with user interaction).
|
||||
|
||||
@@ -68,9 +68,6 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
pub mod authenticator;
|
||||
pub mod authenticator_delegate;
|
||||
mod device;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use crate::error::{JsonErrorOr, RefreshError};
|
||||
use crate::types::ApplicationSecret;
|
||||
use crate::types::{ApplicationSecret, Token};
|
||||
|
||||
use super::Token;
|
||||
use chrono::Utc;
|
||||
use futures_util::try_stream::TryStreamExt;
|
||||
use hyper;
|
||||
use hyper::header;
|
||||
use serde::Deserialize;
|
||||
use url::form_urlencoded;
|
||||
|
||||
/// Implements the [OAuth2 Refresh Token Flow](https://developers.google.com/youtube/v3/guides/authentication#devices).
|
||||
|
||||
@@ -11,29 +11,24 @@
|
||||
//! Copyright (c) 2016 Google Inc (lewinb@google.com).
|
||||
//!
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::authenticator::{DefaultHyperClient, HyperClientBuilder};
|
||||
use crate::error::{Error, JsonErrorOr};
|
||||
use crate::storage::{self, Storage};
|
||||
use crate::types::Token;
|
||||
|
||||
use std::io;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use futures::prelude::*;
|
||||
use hyper::header;
|
||||
use url::form_urlencoded;
|
||||
|
||||
use rustls::{
|
||||
self,
|
||||
internal::pemfile,
|
||||
sign::{self, SigningKey},
|
||||
PrivateKey,
|
||||
};
|
||||
use std::io;
|
||||
|
||||
use base64;
|
||||
use chrono;
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::form_urlencoded;
|
||||
|
||||
const GRANT_TYPE: &str = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
||||
const GOOGLE_RS256_HEAD: &str = r#"{"alg":"RS256","typ":"JWT"}"#;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//
|
||||
// See project root for licensing information.
|
||||
//
|
||||
use crate::types::Token;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
@@ -10,7 +11,7 @@ use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::types::Token;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub struct ScopeHash(u64);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Represents a token as returned by OAuth2 servers.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user