mauth_client/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4use ::reqwest_middleware::ClientWithMiddleware;
5use mauth_core::signer::Signer;
6use mauth_core::verifier::Verifier;
7use reqwest::Url;
8use std::collections::HashMap;
9use std::sync::{LazyLock, OnceLock, RwLock};
10use uuid::Uuid;
11
12/// This is the primary struct of this class. It contains all of the information
13/// required to sign requests using the MAuth protocol and verify the responses.
14///
15/// Note that it contains a cache of response keys for verifying response signatures. This cache
16/// makes the struct non-Sync.
17#[derive(Clone)]
18pub struct MAuthInfo {
19    app_id: Uuid,
20    sign_with_v1_also: bool,
21    signer: Signer,
22    mauth_uri_base: Url,
23    allow_v1_auth: bool,
24}
25
26static CLIENT: OnceLock<ClientWithMiddleware> = OnceLock::new();
27
28static PUBKEY_CACHE: LazyLock<RwLock<HashMap<Uuid, Verifier>>> =
29    LazyLock::new(|| RwLock::new(HashMap::new()));
30
31/// Tower Service and Layer to allow Tower-integrated servers to validate incoming request
32#[cfg(feature = "axum-service")]
33pub mod axum_service;
34/// Helpers to parse configuration files or supply structs and construct instances of the main struct
35pub mod config;
36#[cfg(test)]
37mod protocol_test_suite;
38mod reqwest_middleware;
39/// Implementation of code to sign outgoing requests
40pub mod sign_outgoing;
41/// Implementation of code to validate incoming requests
42#[cfg(feature = "axum-service")]
43pub mod validate_incoming;