aauth 0.0.2

Rust implementation of the AAuth authorization protocol
Documentation
use axum::extract::FromRequestParts;
use axum::http::StatusCode;
use axum::http::request::Parts;

use crate::jwt::VerifiedToken;

pub struct VerifiedAAuthToken(pub VerifiedToken);

impl<S> FromRequestParts<S> for VerifiedAAuthToken
where
    S: Send + Sync,
{
    type Rejection = (StatusCode, String);

    async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
        parts
            .extensions
            .get::<VerifiedToken>()
            .cloned()
            .map(VerifiedAAuthToken)
            .ok_or((
                StatusCode::UNAUTHORIZED,
                "Missing verified AAuth token".into(),
            ))
    }
}