Skip to content

Commit 6c2abc7

Browse files
Merge pull request #15 from mdsol/convert-to-mauth-core
Major upgrade and refactor
2 parents 20483dc + b00e86b commit 6c2abc7

14 files changed

+758
-922
lines changed

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
8+
updates:
9+
- package-ecosystem: cargo
10+
directory: /
11+
schedule:
12+
interval: weekly
13+
14+
- package-ecosystem: github-actions
15+
directory: /
16+
schedule:
17+
interval: weekly

.github/workflows/ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
rustfmt:
18+
name: rustfmt
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions-rust-lang/setup-rust-toolchain@v1
23+
with:
24+
components: rustfmt
25+
- name: Rustfmt Check
26+
uses: actions-rust-lang/rustfmt@v1
27+
28+
clippy:
29+
name: clippy
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
submodules: true
35+
- uses: actions-rust-lang/setup-rust-toolchain@v1
36+
with:
37+
components: clippy
38+
- name: Clippy Check
39+
run: cargo clippy --all-targets --all-features
40+
41+
test:
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 10
44+
45+
concurrency:
46+
# Cancel intermediate builds
47+
group: ${{ github.workflow }}-${{ github.ref }}
48+
cancel-in-progress: true
49+
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
submodules: true
54+
55+
- name: Setup Rust toolchain
56+
uses: dtolnay/rust-toolchain@stable
57+
58+
- uses: Swatinem/rust-cache@v2
59+
60+
- name: Run tests
61+
run: |
62+
cargo test --all-features

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- "*.*.*"
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
name: Build + Publish
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup Rust toolchain
24+
uses: dtolnay/rust-toolchain@stable
25+
26+
- run: cargo publish
27+
env:
28+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

Cargo.toml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mauth-client"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = ["Mason Gup <mgup@mdsol.com>"]
55
edition = "2021"
66
documentation = "https://docs.rs/mauth-client/"
@@ -13,31 +13,25 @@ keywords = ["security", "authentication", "web"]
1313
categories = ["authentication", "web-programming"]
1414

1515
[dependencies]
16-
ring = ">= 0.17.7"
17-
reqwest = { version = ">= 0.11.23", features = ["json"] }
18-
url = ">= 2.5.0"
19-
serde = { version = ">= 1.0.85", features = ["derive"] }
20-
serde_json = ">= 1.0.0"
21-
serde_yaml = ">= 0.8.0"
22-
uuid = { version = ">= 0.21.0", features = ["v4"] }
23-
dirs = ">= 2.0.0"
24-
base64 = ">= 0.10.0"
25-
chrono = ">= 0.4.0"
26-
percent-encoding = ">= 2.0.0"
27-
tokio = { version = ">= 1.0.1", features = ["fs"] }
28-
sha2 = ">= 0.9.0"
29-
hex = ">= 0.4.0"
30-
openssl = ">= 0.10.0"
31-
regex = { version = "1", default_features = false, features = ["std"] }
32-
bytes = ">= 1.0.0"
33-
http = ">= 1.0.0"
34-
tower = { version = ">= 0.4.13", optional = true }
16+
reqwest = { version = "0.12", features = ["json"] }
17+
url = "2"
18+
serde = { version = "1", features = ["derive"] }
19+
serde_json = "1"
20+
serde_yml = "0.0.10"
21+
uuid = { version = "1", features = ["v4"] }
22+
dirs = "5"
23+
chrono = "0.4"
24+
tokio = { version = "1", features = ["fs"] }
25+
tower = { version = "0.4", optional = true }
3526
axum = { version = ">= 0.7.2", optional = true }
36-
futures-core = { version = ">= 0.3.25", optional = true }
37-
thiserror = ">= 1.0.37"
27+
futures-core = { version = "0.3", optional = true }
28+
http = { version = "1", optional = true }
29+
bytes = { version = "1", optional = true }
30+
thiserror = "1"
31+
mauth-core = "0.5"
3832

3933
[dev-dependencies]
40-
tokio = { version = ">= 1.0.1", features = ["rt-multi-thread", "macros"] }
34+
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
4135

4236
[features]
43-
axum-service = ["tower", "futures-core", "axum"]
37+
axum-service = ["tower", "futures-core", "axum", "http", "bytes"]

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@ release any code to Production or deploy in a Client-accessible environment with
1010
approval for the full stack used through the Architecture and Security groups.
1111

1212
```rust
13+
use mauth_client::MAuthInfo;
14+
use reqwest::Client;
1315
let mauth_info = MAuthInfo::from_default_file().unwrap();
1416
let client = Client::new();
15-
let uri: Url = "https://www.example.com/".parse().unwrap();
16-
let (body, body_digest) = MAuthInfo::build_body_with_digest("".to_string());
17-
let mut req = Request::new(Method::GET, uri);
18-
*req.body_mut() = Some(body);
19-
mauth_info.sign_request(&mut req, &body_digest);
17+
let mut req = client.get("https://www.example.com/").build().unwrap();
18+
mauth_info.sign_request(&mut req);
2019
match client.execute(req).await {
2120
Err(err) => println!("Got error {}", err),
22-
Ok(response) => match mauth_info.validate_response(response).await {
23-
Ok(resp_body) => println!(
24-
"Got validated response with body {}",
25-
&String::from_utf8(resp_body).unwrap()
26-
),
27-
Err(err) => println!("Error validating response: {:?}", err),
28-
}
21+
Ok(response) => println!("Got validated response with body {}", response.text().await.unwrap()),
2922
}
3023
```
3124

25+
26+
The above code will read your mauth configuration from a file in `~/.mauth_config.yml` which format is:
27+
```yaml
28+
common: &common
29+
mauth_baseurl: https://<URL of MAUTH SERVER>
30+
mauth_api_version: v1
31+
app_uuid: <YOUR APP UUID HERE>
32+
private_key_file: <PATH TO MAUTH KEY>
33+
```
34+
3235
The optional `axum-service` feature provides for a Tower Layer and Service that will
3336
authenticate incoming requests via MAuth V2 or V1 and provide to the lower layers a
3437
validated app_uuid from the request via the ValidatedRequestDetails struct.

build.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ fn main() {
2525
let formatted_name = name.replace('-', "_");
2626
code_str.push_str(&format!(
2727
r#"
28-
#[tokio::test]
29-
async fn {formatted_name}_string_to_sign() {{
30-
test_string_to_sign("{name}".to_string()).await;
31-
}}
32-
33-
#[tokio::test]
34-
async fn {formatted_name}_sign_string() {{
35-
test_sign_string("{name}".to_string()).await;
36-
}}
37-
3828
#[tokio::test]
3929
async fn {formatted_name}_generate_headers() {{
4030
test_generate_headers("{name}".to_string()).await;

src/axum_service.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
33
use axum::extract::Request;
44
use futures_core::future::BoxFuture;
5-
use openssl::{pkey::Public, rsa::Rsa};
5+
use mauth_core::verifier::Verifier;
66
use std::collections::HashMap;
77
use std::error::Error;
88
use std::sync::{Arc, RwLock};
99
use std::task::{Context, Poll};
1010
use tower::{Layer, Service};
1111
use uuid::Uuid;
1212

13-
use crate::{ConfigFileSection, ConfigReadError, MAuthInfo};
13+
use crate::{
14+
config::{ConfigFileSection, ConfigReadError},
15+
MAuthInfo,
16+
};
1417

1518
/// This is a Tower Service which validates that incoming requests have a valid
1619
/// MAuth signature. It only passes the request down to the next layer if the
@@ -69,7 +72,7 @@ impl<S: Clone> Clone for MAuthValidationService<S> {
6972
#[derive(Clone)]
7073
pub struct MAuthValidationLayer {
7174
config_info: ConfigFileSection,
72-
remote_key_store: Arc<RwLock<HashMap<Uuid, Rsa<Public>>>>,
75+
remote_key_store: Arc<RwLock<HashMap<Uuid, Verifier>>>,
7376
}
7477

7578
impl<S> Layer<S> for MAuthValidationLayer {

0 commit comments

Comments
 (0)