Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #140

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ replicate the old behaviour, its body should simply consist of `Err(())`.

## v0.4.5

An empty `refresh` token in the `IssuedToken` will no longer inidicate support
An empty `refresh` token in the `IssuedToken` will no longer indicate support
for refreshing to the client. Furthermore, refresh tokens need to be
explicitely enabled for `TokenSigner` as there is no good way to revoke them
explicitly enabled for `TokenSigner` as there is no good way to revoke them
and are mostly intended for usage in custom signers.

## v0.4.1
Expand All @@ -66,7 +66,7 @@ larger code bases would be implementing `endpoint::Endpoint` yourself.

Note that `MethodAuthorizer` got replaced by `frontends::simple::FnSolicitor`
and the `IronAuthorizer` has been fully removed. `SimpleAuthorization` was
superseeded by `endpoint::OwnerAuthorization`.
superseded by `endpoint::OwnerAuthorization`.

Support for a Bearer token authorizing Middleware implementation has not yet
been implemented. Also, see the notes on `QueryParamter` and module reordering
Expand Down Expand Up @@ -94,7 +94,7 @@ multiple independent extensions at the same time, this is no longer required
for other frontends. The data portion of a `GrantExtension` has been renamed to
the more unique `Value`, and the `simple` extension module extends on this
trait to offer `AccessTokenAddon` and `AuthorizationAddon`, simple traits to
implement only a portion of a fullblown system of extension at a time.
implement only a portion of a full-blown system of extension at a time.

Serde support for `NormalizedParameter` so that there is less confusion about
how to construct them and the potential pitfalls of dropping duplicate
Expand Down Expand Up @@ -171,7 +171,7 @@ The following names have changed for consistency:
### Actix frontend

The standardization of a simple, reusable `Endpoint` offers exiting new
possibilites. Foremost, a simple newtype wrapper around this and other
possibilities. Foremost, a simple newtype wrapper around this and other
primitives imbues them with `Actor` powers and messaging. Requests and
responses are now more composable so the former now has a simpler
representation and the necessity of tacking on owner owner consent information
Expand All @@ -184,7 +184,7 @@ The initial construction of a `OAuthRequest` is now the result of an
the actix message constructors. Since `OAuthRequest` now also implements
`WebRequest` in a simple manner, many implementors will likely want to use a
newtype style to further customize error types and response representations.
Keep in mind that for a request to be useable as a message to an endpoint
Keep in mind that for a request to be usable as a message to an endpoint
actor, the error types of the two have to agree. This restriction may be lifted
in later versions.

Expand Down Expand Up @@ -337,7 +337,7 @@ of the endpoint does that conversion.
Rationale: The trait bounds puts some restrictions on implementing endpoints
with error types that are not defined in the current trait. Additionally, it
made it impossible to generalize over the underlying request type, as there is
no way to implemention `impl<T> From<T> for ErrorType`, of course.
no way to implement `impl<T> From<T> for ErrorType`, of course.

----

Expand All @@ -349,7 +349,7 @@ traits `AuthorizationExtension` etc. have been moved to the new
frontend.

Rationale: This is to allow groups of extensions working closely together, such
as possibly for OpenID in the future. It also solves a few efficieny and design
as possibly for OpenID in the future. It also solves a few efficient and design
issues by leaving the representation more open to library users/frontends.
Since extension do not provide guarantees on idempotency, they can not be
simply retried. Therefore, the asynchronous interface of actix can not
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ easiest way to track its progress is by opening a tracking issue.

In case you already have working code - even better. Simply link the pull
request in the issue. If you have not done so already, you _may_ also add
yourself to the [list of constributors][contributors] (that's up to You, there
yourself to the [list of contributors][contributors] (that's up to You, there
is no need to so).

Please respect that I maintain this on my own currently and have limited time.
Expand Down
24 changes: 14 additions & 10 deletions examples/support/generic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Helper methods for several examples.
//!
//! The support files for each frontend include a client instance for several implemented
//! frontends. These are not part of the main example code as this library focusses purely on the
//! frontends. These are not part of the main example code as this library focuses purely on the
//! server side. This module contains code that can be shared between the different frontends.
//! Since we want to be able to run the actix example but share it with rocket examples but
//! rocket includes macros in its crate root, the module include order is a bit strange.
Expand All @@ -11,7 +11,7 @@
#![allow(unused)]

/// Simplistic reqwest client.
#[path="./client.rs"]
#[path = "./client.rs"]
mod client;

use oxide_auth::endpoint::Solicitation;
Expand Down Expand Up @@ -39,19 +39,22 @@ pub fn open_in_browser() {
Err(Error::new(ErrorKind::Other, "Open not supported"))
};

open_with.and_then(|cmd| Command::new(cmd).arg(target_addres).status())
.and_then(|status| if status.success() {
Ok(())
} else {
Err(Error::new(ErrorKind::Other, "Non zero status"))
open_with
.and_then(|cmd| Command::new(cmd).arg(target_addres).status())
.and_then(|status| {
if status.success() {
Ok(())
} else {
Err(Error::new(ErrorKind::Other, "Non zero status"))
}
})
.unwrap_or_else(|_| println!("Please navigate to {}", target_addres));
}

pub fn consent_page_html(route: &str, solicitation: Solicitation) -> String {
macro_rules! template {
() => {
"<html>'{0:}' (at {1:}) is requesting permission for '{2:}'
"<html>'{0:}' (at {1:}) is requesting permission for '{2:}'
<form method=\"post\">
<input type=\"submit\" value=\"Accept\" formaction=\"{4:}?{3:}&allow=true\">
<input type=\"submit\" value=\"Deny\" formaction=\"{4:}?{3:}&deny=true\">
Expand All @@ -72,8 +75,9 @@ pub fn consent_page_html(route: &str, solicitation: Solicitation) -> String {
if let Some(state) = state {
extra.push(("state", state));
}

format!(template!(),

format!(
template!(),
grant.client_id,
grant.redirect_uri,
grant.scope,
Expand Down
4 changes: 2 additions & 2 deletions oxide-auth-actix/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxide-auth-actix"
version = "0.2.0"
version = "0.3.0"
authors = ["Andreas Molzer <andreas.molzer@gmx.de>"]
repository = "https://github.com/HeroicKatora/oxide-auth.git"

Expand All @@ -15,7 +15,7 @@ edition = "2018"
actix = { version = "0.12", default-features = false }
actix-web = { version = "4.0.1", default-features = false }
futures = "0.3"
oxide-auth = { version = "0.5.0", path = "../oxide-auth" }
oxide-auth = { version = "0.6", path = "../oxide-auth" }
serde_urlencoded = "0.7"
url = "2"

Expand Down
4 changes: 4 additions & 0 deletions oxide-auth-actix/Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0
- Fixed clippy errors
- Turned some `Into` implementations into `From` implementations

## 0.2.0

- Now compatible to `actix = "4"`.
Expand Down
4 changes: 2 additions & 2 deletions oxide-auth-actix/examples/actix-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ actix = "0.12"
actix-web = "4.0.1"
env_logger = "0.7"
futures = "0.3"
oxide-auth = { version = "0.5.0", path = "./../../../oxide-auth" }
oxide-auth-actix = { version = "0.2.0", path = "./../../" }
oxide-auth = { version = "0.6", path = "./../../../oxide-auth" }
oxide-auth-actix = { version = "0.3.0", path = "./../../../oxide-auth-actix" }
reqwest = "=0.9.5"
serde = "1.0"
serde_json = "1.0"
Expand Down
42 changes: 20 additions & 22 deletions oxide-auth-actix/examples/actix-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ here</a> to begin the authorization process.
</html>
";

pub type GenericEndpoint = Generic<
ClientMap,
AuthMap<RandomGenerator>,
TokenMap<RandomGenerator>,
Vacant,
Vec<Scope>,
fn() -> OAuthResponse,
>;

struct State {
endpoint: Generic<
ClientMap,
AuthMap<RandomGenerator>,
TokenMap<RandomGenerator>,
Vacant,
Vec<Scope>,
fn() -> OAuthResponse,
>,
endpoint: GenericEndpoint,
}

enum Extras {
Expand All @@ -42,7 +44,7 @@ enum Extras {
}

async fn get_authorize(
(req, state): (OAuthRequest, web::Data<Addr<State>>),
(req, state): (OAuthRequest, Data<Addr<State>>),
) -> Result<OAuthResponse, WebError> {
// GET requests should not mutate server state and are extremely
// vulnerable accidental repetition as well as Cross-Site Request
Expand All @@ -51,27 +53,23 @@ async fn get_authorize(
}

async fn post_authorize(
(r, req, state): (HttpRequest, OAuthRequest, web::Data<Addr<State>>),
(r, req, state): (HttpRequest, OAuthRequest, Data<Addr<State>>),
) -> Result<OAuthResponse, WebError> {
// Some authentication should be performed here in production cases
state
.send(Authorize(req).wrap(Extras::AuthPost(r.query_string().to_owned())))
.await?
}

async fn token((req, state): (OAuthRequest, web::Data<Addr<State>>)) -> Result<OAuthResponse, WebError> {
async fn token((req, state): (OAuthRequest, Data<Addr<State>>)) -> Result<OAuthResponse, WebError> {
state.send(Token(req).wrap(Extras::Nothing)).await?
}

async fn refresh(
(req, state): (OAuthRequest, web::Data<Addr<State>>),
) -> Result<OAuthResponse, WebError> {
async fn refresh((req, state): (OAuthRequest, Data<Addr<State>>)) -> Result<OAuthResponse, WebError> {
state.send(Refresh(req).wrap(Extras::Nothing)).await?
}

async fn index(
(req, state): (OAuthResource, web::Data<Addr<State>>),
) -> Result<OAuthResponse, WebError> {
async fn index((req, state): (OAuthResource, Data<Addr<State>>)) -> Result<OAuthResponse, WebError> {
match state
.send(Resource(req.into_request()).wrap(Extras::Nothing))
.await?
Expand All @@ -84,7 +82,7 @@ async fn index(
}
}

async fn start_browser() -> () {
async fn start_browser() {
let _ = thread::spawn(support::open_in_browser);
}

Expand Down Expand Up @@ -161,9 +159,9 @@ impl State {
}
}

pub fn with_solicitor<'a, S>(
&'a mut self, solicitor: S,
) -> impl Endpoint<OAuthRequest, Error = WebError> + 'a
pub fn with_solicitor<S>(
&'_ mut self, solicitor: S,
) -> impl Endpoint<OAuthRequest, Error = WebError> + '_
where
S: OwnerSolicitor<OAuthRequest> + 'static,
{
Expand Down Expand Up @@ -200,7 +198,7 @@ where
OAuthResponse::ok()
.content_type("text/html")
.unwrap()
.body(&crate::support::consent_page_html("/authorize".into(), pre_grant)),
.body(&support::consent_page_html("/authorize", pre_grant)),
)
});

Expand Down
6 changes: 3 additions & 3 deletions oxide-auth-actix/examples/actix-example/src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn dummy_client() -> dev::Server {
}

async fn endpoint_impl(
(query, state): (web::Query<HashMap<String, String>>, web::Data<Client>),
(query, state): (web::Query<HashMap<String, String>>, Data<Client>),
) -> impl Responder {
if let Some(cause) = query.get("error") {
return HttpResponse::BadRequest()
Expand All @@ -56,14 +56,14 @@ async fn endpoint_impl(
}
}

async fn refresh(state: web::Data<Client>) -> impl Responder {
async fn refresh(state: Data<Client>) -> impl Responder {
match state.refresh() {
Ok(()) => HttpResponse::Found().append_header(("Location", "/")).finish(),
Err(err) => HttpResponse::InternalServerError().body(format!("{}", err)),
}
}

async fn get_with_token(state: web::Data<Client>) -> impl Responder {
async fn get_with_token(state: Data<Client>) -> impl Responder {
let protected_page = match state.retrieve_protected_page() {
Ok(page) => page,
Err(err) => return HttpResponse::InternalServerError().body(format!("{}", err)),
Expand Down
10 changes: 6 additions & 4 deletions oxide-auth-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ pub struct OAuthResponse {
#[derive(Debug)]
/// The error type for Oxide Auth operations
pub enum WebError {
/// Errors occuring in Endpoint operations
/// Errors occurring in Endpoint operations
Endpoint(OAuthError),

/// Errors occuring when producing Headers
/// Errors occurring when producing Headers
Header(InvalidHeaderValue),

/// Errors with the request encoding
Expand Down Expand Up @@ -447,8 +447,10 @@ impl fmt::Display for WebError {
WebError::Authorization => write!(f, "Request has invalid Authorization headers"),
WebError::Canceled => write!(f, "Operation canceled"),
WebError::Mailbox => write!(f, "An actor's mailbox was full"),
WebError::InternalError(None) => write!(f, "An internal server error occured"),
WebError::InternalError(Some(ref e)) => write!(f, "An internal server error occured: {}", e),
WebError::InternalError(None) => write!(f, "An internal server error occurred"),
WebError::InternalError(Some(ref e)) => {
write!(f, "An internal server error occurred: {}", e)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions oxide-auth-async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxide-auth-async"
version = "0.1.0"
version = "0.3.0"
authors = ["Andreas Molzer <andreas.molzer@gmx.de>"]
repository = "https://github.com/HeroicKatora/oxide-auth.git"

Expand All @@ -13,7 +13,7 @@ edition = "2018"

[dependencies]
async-trait = "0.1.21"
oxide-auth = { version = "0.5.0", path = "../oxide-auth" }
oxide-auth = { version = "0.6", path = "../oxide-auth" }
base64 = "0.12"
url = "2"
chrono = "0.4.2"
Expand Down
16 changes: 7 additions & 9 deletions oxide-auth-async/src/code_grant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub mod resource {
pub mod access_token {
use async_trait::async_trait;
use oxide_auth::{
code_grant::accesstoken::{
code_grant::access_token::{
AccessToken, BearerToken, Error, Input, Output, PrimitiveError, Request as TokenRequest,
},
primitives::{
Expand All @@ -149,14 +149,14 @@ pub mod access_token {
/// authorization code request.
async fn extend(
&mut self, request: &(dyn TokenRequest + Sync), data: Extensions,
) -> std::result::Result<Extensions, ()>;
) -> Result<Extensions, ()>;
}

#[async_trait]
impl Extension for () {
async fn extend(
&mut self, _: &(dyn TokenRequest + Sync), _: Extensions,
) -> std::result::Result<Extensions, ()> {
) -> Result<Extensions, ()> {
Ok(Extensions::new())
}
}
Expand Down Expand Up @@ -286,14 +286,12 @@ pub mod authorization {
#[async_trait]
pub trait Extension {
/// Inspect the request to produce extension data.
async fn extend(
&mut self, request: &(dyn Request + Sync),
) -> std::result::Result<Extensions, ()>;
async fn extend(&mut self, request: &(dyn Request + Sync)) -> Result<Extensions, ()>;
}

#[async_trait]
impl Extension for () {
async fn extend(&mut self, _: &(dyn Request + Sync)) -> std::result::Result<Extensions, ()> {
async fn extend(&mut self, _: &(dyn Request + Sync)) -> Result<Extensions, ()> {
Ok(Extensions::new())
}
}
Expand All @@ -317,7 +315,7 @@ pub mod authorization {
}

/// Represents a valid, currently pending authorization request not bound to an owner. The frontend
/// can signal a reponse using this object.
/// can signal a response using this object.
#[derive(Clone)]
pub struct Pending {
pre_grant: PreGrant,
Expand Down Expand Up @@ -382,7 +380,7 @@ pub mod authorization {

/// Retrieve allowed scope and redirect url from the registrar.
///
/// Checks the validity of any given input as the registrar instance communicates the registrated
/// Checks the validity of any given input as the registrar instance communicates the registered
/// parameters. The registrar can also set or override the requested (default) scope of the client.
/// This will result in a tuple of negotiated parameters which can be used further to authorize
/// the client by the owner or, in case of errors, in an action to be taken.
Expand Down
Loading