Skip to content

Commit

Permalink
Reorder and clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ramosbugs committed Feb 25, 2024
1 parent 553a9a4 commit 438e5d1
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 85 deletions.
4 changes: 2 additions & 2 deletions examples/msgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ use oauth2::{
AuthType, AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, PkceCodeChallenge,
RedirectUrl, Scope, TokenUrl,
};
use url::Url;

use std::env;
use std::io::{BufRead, BufReader, Write};
use std::net::TcpListener;

use url::Url;

fn main() {
let graph_client_id = ClientId::new(
env::var("MSGRAPH_CLIENT_ID").expect("Missing the MSGRAPH_CLIENT_ID environment variable."),
Expand Down
13 changes: 5 additions & 8 deletions src/basic.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use std::fmt::Error as FormatterError;
use std::fmt::{Debug, Display, Formatter};

use super::{
Client, EmptyExtraTokenFields, ErrorResponseType, RequestTokenError, StandardErrorResponse,
StandardTokenResponse, TokenType,
};
use crate::{
revocation::{RevocationErrorResponseType, StandardRevocableToken},
StandardTokenIntrospectionResponse,
Client, EmptyExtraTokenFields, ErrorResponseType, RequestTokenError, StandardErrorResponse,
StandardTokenIntrospectionResponse, StandardTokenResponse, TokenType,
};

use std::fmt::Error as FormatterError;
use std::fmt::{Debug, Display, Formatter};

/// Basic OAuth2 client specialization, suitable for most applications.
pub type BasicClient<
const HAS_AUTH_URL: bool = false,
Expand Down
4 changes: 2 additions & 2 deletions src/curl.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::io::Read;
use crate::{HttpRequest, HttpResponse};

use curl::easy::Easy;
use http::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use http::method::Method;
use http::status::StatusCode;

use super::{HttpRequest, HttpResponse};
use std::io::Read;

/// Error type returned by failed curl HTTP requests.
#[derive(Debug, thiserror::Error)]
Expand Down
20 changes: 10 additions & 10 deletions src/devicecode.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::basic::BasicErrorResponseType;
use crate::types::VerificationUriComplete;
use crate::{
DeviceCode, EndUserVerificationUrl, ErrorResponse, ErrorResponseType, RequestTokenError,
StandardErrorResponse, TokenResponse, TokenType, UserCode,
};

use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

use std::error::Error;
use std::fmt::Error as FormatterError;
use std::fmt::{Debug, Display, Formatter};
use std::marker::PhantomData;
use std::time::Duration;

use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

use super::{
DeviceCode, EndUserVerificationUrl, ErrorResponse, ErrorResponseType, RequestTokenError,
StandardErrorResponse, TokenResponse, TokenType, UserCode,
};
use crate::basic::BasicErrorResponseType;
use crate::types::VerificationUriComplete;

/// The minimum amount of time in seconds that the client SHOULD wait
/// between polling requests to the token endpoint. If no value is
/// provided, clients MUST use 5 as the default.
Expand Down
39 changes: 19 additions & 20 deletions src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use serde::de::value::SeqAccessDeserializer;
use serde::ser::{Impossible, SerializeStructVariant, SerializeTupleVariant};
use serde::{de, ser};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use serde_json::Value;

use std::error::Error;
use std::fmt::{Display, Formatter};
use std::marker::PhantomData;

/// Serde case-insensitive deserializer for an untagged `enum`.
Expand Down Expand Up @@ -45,12 +48,10 @@ where
T: Deserialize<'de>,
D: Deserializer<'de>,
{
use serde::de::Error;
use serde_json::Value;
T::deserialize(Value::String(
String::deserialize(deserializer)?.to_lowercase(),
))
.map_err(Error::custom)
.map_err(serde::de::Error::custom)
}

/// Serde space-delimited string deserializer for a `Vec<String>`.
Expand Down Expand Up @@ -89,14 +90,12 @@ where
T: Default + Deserialize<'de>,
D: Deserializer<'de>,
{
use serde::de::Error;
use serde_json::Value;
if let Some(space_delimited) = Option::<String>::deserialize(deserializer)? {
let entries = space_delimited
.split(' ')
.map(|s| Value::String(s.to_string()))
.collect();
T::deserialize(Value::Array(entries)).map_err(Error::custom)
T::deserialize(Value::Array(entries)).map_err(serde::de::Error::custom)
} else {
// If the JSON value is null, use the default value.
Ok(T::default())
Expand All @@ -112,39 +111,39 @@ where
{
struct StringOrVec(PhantomData<Vec<String>>);

impl<'de> de::Visitor<'de> for StringOrVec {
impl<'de> serde::de::Visitor<'de> for StringOrVec {
type Value = Option<Vec<String>>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
formatter.write_str("string or list of strings")
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
E: serde::de::Error,
{
Ok(Some(vec![value.to_owned()]))
}

fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
E: serde::de::Error,
{
Ok(None)
}

fn visit_unit<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
E: serde::de::Error,
{
Ok(None)
}

fn visit_seq<S>(self, visitor: S) -> Result<Self::Value, S::Error>
where
S: de::SeqAccess<'de>,
S: serde::de::SeqAccess<'de>,
{
Deserialize::deserialize(de::value::SeqAccessDeserializer::new(visitor)).map(Some)
Deserialize::deserialize(SeqAccessDeserializer::new(visitor)).map(Some)
}
}

Expand Down Expand Up @@ -181,18 +180,18 @@ pub fn variant_name<T: Serialize>(t: &T) -> &'static str {
#[derive(Debug)]
struct NotEnum;
type Result<T> = std::result::Result<T, NotEnum>;
impl std::error::Error for NotEnum {
impl Error for NotEnum {
fn description(&self) -> &str {
"not struct"
}
}
impl std::fmt::Display for NotEnum {
fn fmt(&self, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl Display for NotEnum {
fn fmt(&self, _f: &mut Formatter) -> std::fmt::Result {
unimplemented!()
}
}
impl ser::Error for NotEnum {
fn custom<T: std::fmt::Display>(_msg: T) -> Self {
impl serde::ser::Error for NotEnum {
fn custom<T: Display>(_msg: T) -> Self {
NotEnum
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,7 @@
//!
//! - [`actix-web-oauth2`](https://github.com/pka/actix-web-oauth2) (version 2.x of this crate)
//!
use std::borrow::Cow;
use std::error::Error;
use std::fmt::Error as FormatterError;
use std::fmt::{Debug, Display, Formatter};
use std::future::Future;
use std::marker::PhantomData;
use std::sync::Arc;
use std::time::Duration;
use crate::devicecode::DeviceAccessTokenPollResult;

use chrono::serde::ts_seconds_option;
use chrono::{DateTime, Utc};
Expand All @@ -430,7 +423,14 @@ use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use url::{form_urlencoded, Url};

use crate::devicecode::DeviceAccessTokenPollResult;
use std::borrow::Cow;
use std::error::Error;
use std::fmt::Error as FormatterError;
use std::fmt::{Debug, Display, Formatter};
use std::future::Future;
use std::marker::PhantomData;
use std::sync::Arc;
use std::time::Duration;

/// Basic OAuth2 implementation with no extensions
/// ([RFC 6749](https://tools.ietf.org/html/rfc6749)).
Expand Down
8 changes: 4 additions & 4 deletions src/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub use async_client::async_http_client;

#[cfg(not(target_arch = "wasm32"))]
mod blocking {
use super::super::{HttpRequest, HttpResponse};
use super::Error;
use crate::reqwest::Error;
use crate::{HttpRequest, HttpResponse};

pub use reqwest;
use reqwest::blocking;
Expand Down Expand Up @@ -59,8 +59,8 @@ mod blocking {
}

mod async_client {
use super::super::{HttpRequest, HttpResponse};
use super::Error;
use crate::reqwest::Error;
use crate::{HttpRequest, HttpResponse};

pub use reqwest;

Expand Down
7 changes: 4 additions & 3 deletions src/revocation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{basic::BasicErrorResponseType, ErrorResponseType};
use crate::{AccessToken, RefreshToken};

use serde::{Deserialize, Serialize};

use std::fmt::Error as FormatterError;
use std::fmt::{Debug, Display, Formatter};

use crate::{basic::BasicErrorResponseType, ErrorResponseType};
use crate::{AccessToken, RefreshToken};

/// A revocable token.
///
/// Implement this trait to indicate support for token revocation per [RFC 7009 OAuth 2.0 Token Revocation](https://tools.ietf.org/html/rfc7009#section-2.2).
Expand Down
Loading

0 comments on commit 438e5d1

Please sign in to comment.