Skip to content

Commit

Permalink
Merge pull request #14 from mdsol/to-axum
Browse files Browse the repository at this point in the history
Update to support current HTTP/Hyper ecosystem
  • Loading branch information
masongup-mdsol authored Jan 4, 2024
2 parents c1da825 + eeb1f81 commit 20483dc
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 135 deletions.
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mauth-client"
version = "0.2.0"
version = "0.3.0"
authors = ["Mason Gup <[email protected]>"]
edition = "2021"
documentation = "https://docs.rs/mauth-client/"
Expand All @@ -13,9 +13,9 @@ keywords = ["security", "authentication", "web"]
categories = ["authentication", "web-programming"]

[dependencies]
ring = ">= 0.16.19"
hyper = { version = ">= 0.14.2", features = ["client", "http1"] }
hyper-tls = ">= 0.5.0"
ring = ">= 0.17.7"
reqwest = { version = ">= 0.11.23", features = ["json"] }
url = ">= 2.5.0"
serde = { version = ">= 1.0.85", features = ["derive"] }
serde_json = ">= 1.0.0"
serde_yaml = ">= 0.8.0"
Expand All @@ -30,13 +30,14 @@ hex = ">= 0.4.0"
openssl = ">= 0.10.0"
regex = { version = "1", default_features = false, features = ["std"] }
bytes = ">= 1.0.0"
http = ">= 0.2.3"
http = ">= 1.0.0"
tower = { version = ">= 0.4.13", optional = true }
axum = { version = ">= 0.7.2", optional = true }
futures-core = { version = ">= 0.3.25", optional = true }
thiserror = ">= 1.0.37"

[dev-dependencies]
tokio = { version = ">= 1.0.1", features = ["rt-multi-thread", "macros"] }

[features]
tower-service = ["tower", "futures-core"]
axum-service = ["tower", "futures-core", "axum"]
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## mauth-client

This crate allows users of the Hyper crate for making HTTP requests to sign those requests with
This crate allows users of the Reqwest crate for making HTTP requests to sign those requests with
the MAuth protocol, and verify the responses. Usage example:

**Note**: This crate and Rust support within Medidata is considered experimental. Do not
Expand All @@ -11,29 +11,26 @@ approval for the full stack used through the Architecture and Security groups.

```rust
let mauth_info = MAuthInfo::from_default_file().unwrap();
let https = HttpsConnector::new();
let client = Client::builder().build::<_, hyper::Body>(https);
let uri: hyper::Uri = "https://www.example.com/".parse().unwrap();
let client = Client::new();
let uri: Url = "https://www.example.com/".parse().unwrap();
let (body, body_digest) = MAuthInfo::build_body_with_digest("".to_string());
let mut req = Request::new(body);
*req.method_mut() = Method::GET;
*req.uri_mut() = uri.clone();
let mut req = Request::new(Method::GET, uri);
*req.body_mut() = Some(body);
mauth_info.sign_request(&mut req, &body_digest);
match client.request(req).await {
match client.execute(req).await {
Err(err) => println!("Got error {}", err),
Ok(mut response) => match mauth_info.validate_response(&mut response).await {
Ok(response) => match mauth_info.validate_response(response).await {
Ok(resp_body) => println!(
"Got validated response with status {} and body {}",
&response.status().as_str(),
"Got validated response with body {}",
&String::from_utf8(resp_body).unwrap()
),
Err(err) => println!("Error validating response: {:?}", err),
}
}
```

The optional `tower-service` feature provides for a Tower Layer and Service that will
authenticate incoming requests via MAuth V2 or V2 and provide to the lower layers a
The optional `axum-service` feature provides for a Tower Layer and Service that will
authenticate incoming requests via MAuth V2 or V1 and provide to the lower layers a
validated app_uuid from the request via the ValidatedRequestDetails struct.

License: MIT
8 changes: 4 additions & 4 deletions src/tower.rs → src/axum_service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Structs and impls related to providing a Tower Service and Layer to verify incoming requests
use axum::extract::Request;
use futures_core::future::BoxFuture;
use hyper::{body::Body, Request};
use openssl::{pkey::Public, rsa::Rsa};
use std::collections::HashMap;
use std::error::Error;
Expand All @@ -21,9 +21,9 @@ pub struct MAuthValidationService<S> {
service: S,
}

impl<S> Service<Request<Body>> for MAuthValidationService<S>
impl<S> Service<Request> for MAuthValidationService<S>
where
S: Service<Request<Body>> + Send + Clone + 'static,
S: Service<Request> + Send + Clone + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn Error + Sync + Send>>,
{
Expand All @@ -35,7 +35,7 @@ where
self.service.poll_ready(cx).map_err(|e| e.into())
}

fn call(&mut self, request: Request<Body>) -> Self::Future {
fn call(&mut self, request: Request) -> Self::Future {
let mut cloned = self.clone();
Box::pin(async move {
match cloned.mauth_info.validate_request(request).await {
Expand Down
Loading

0 comments on commit 20483dc

Please sign in to comment.