Skip to main content

FapiManager

Struct FapiManager 

Source
pub struct FapiManager { /* private fields */ }
Expand description

FAPI 2.0 Security Profile Manager

§Rate limiting

FapiManager has no rate limiter of its own, and the crate’s HTTP router does not serve FAPI routes, so nothing in the crate limits validate_authorization_request, validate_token_request, authenticate_client_jwt or validate_sender_constrained_token. These do signature work and keep per-request state (a DPoP proof and its replay record) before the caller is authenticated, so put a limiter in front of the FAPI /authorize and /token endpoints yourself: one bucket per caller address, counted before any signature check, and one per authenticated client, counted after client authentication succeeded, with a separate allowance for each endpoint. If the limiter cannot be consulted, refuse the request rather than serve it unlimited. See docs/FAPI_RATE_LIMIT_DESIGN.md.

To have the manager count for you, give it a limiter with FapiManager::with_rate_limiter and call FapiManager::validate_authorization_request_from and FapiManager::validate_token_request_from with the caller’s address; the methods without _from never consult it.

Implementations§

Source§

impl FapiManager

Source

pub fn new( config: FapiConfig, dpop_manager: Arc<DpopManager>, mtls_manager: Arc<MutualTlsManager>, par_manager: Arc<PARManager>, private_key_jwt_manager: Arc<PrivateKeyJwtManager>, jwt_validator: Arc<SecureJwtValidator>, ) -> Self

Create a new FAPI manager

Source

pub fn with_rate_limiter(self, limiter: Arc<DistributedRateLimiter>) -> Self

Count requests made through validate_authorization_request_from and validate_token_request_from against limiter.

Two kinds of bucket live in the limiter: fapi:<authorize|token>:<peer> per caller address, counted before any signature work, and fapi_client:<client id> per authenticated client, counted only after the client proved who it is, so a third party cannot spend a client’s allowance by naming it. The limiter’s configuration sets the allowance. A limiter that cannot be consulted refuses the request. The methods without _from never consult it.

Source

pub async fn validate_authorization_request_from( &self, peer: &str, request_object: &str, client_cert: Option<&str>, dpop_proof: Option<&str>, request_uri: Option<&str>, ) -> Result<FapiRequestObject>

Like validate_authorization_request, counting the request against the caller address peer first and, once the request object is valid, against its client.

Source

pub async fn validate_authorization_request( &self, request_object: &str, client_cert: Option<&str>, dpop_proof: Option<&str>, request_uri: Option<&str>, ) -> Result<FapiRequestObject>

Validate FAPI 2.0 authorization request

Source

pub async fn authenticate_client_jwt( &self, client_assertion: &str, ) -> Result<String>

Authenticate client using private key JWT (RFC 7523)

The caller learns only that authentication failed: the detailed reasons (unknown client, bad signature, wrong audience, replay, …) are logged, never returned.

Source

pub async fn validate_token_request( &self, client_assertion: Option<&str>, client_cert: Option<&str>, dpop_proof: Option<&str>, _authorization_code: &str, ) -> Result<String>

Validate FAPI token request with enhanced security

Source

pub async fn validate_token_request_from( &self, peer: &str, client_assertion: Option<&str>, client_cert: Option<&str>, dpop_proof: Option<&str>, _authorization_code: &str, ) -> Result<String>

Like validate_token_request, counting the request against the caller address peer before any signature work, and against the client’s own bucket once the client has authenticated (before the DPoP check).

Source

pub async fn generate_authorization_response( &self, client_id: &str, code: Option<&str>, state: Option<&str>, error: Option<&str>, error_description: Option<&str>, ) -> Result<String>

Generate FAPI 2.0 authorization response (JARM)

Source

pub async fn generate_token_response( &self, client_id: &str, user_id: &str, scopes: Vec<String>, cert_thumbprint: Option<String>, dpop_jkt: Option<String>, ) -> Result<FapiTokenResponse>

Generate FAPI 2.0 token response

Source

pub async fn create_session( &self, client_id: &str, user_id: &str, scopes: Vec<String>, dpop_proof: Option<String>, cert_thumbprint: Option<String>, request_jti: Option<String>, ) -> Result<String>

Create FAPI session

Source

pub async fn get_session(&self, session_id: &str) -> Result<Option<FapiSession>>

Get FAPI session

Source

pub async fn validate_session(&self, session_id: &str) -> Result<FapiSession>

Validate FAPI session

Source

pub async fn remove_session(&self, session_id: &str) -> Result<()>

Remove FAPI session

Source

pub async fn audit_log(&self, event: &str, details: &Value) -> Result<()>

Audit log entry for FAPI compliance

Source

pub fn check_compliance(&self) -> Vec<FapiComplianceViolation>

Validate FAPI 2.0 compliance of the current configuration.

Returns a list of compliance violations. An empty list means the configuration is fully FAPI 2.0 compliant.

Source

pub fn is_compliant(&self) -> bool

Returns true if the configuration is fully FAPI 2.0 compliant (no critical violations).

Source

pub async fn validate_sender_constrained_token( &self, access_token: &str, dpop_proof: Option<&str>, client_cert: Option<&str>, http_method: &str, http_uri: &str, ) -> Result<Value>

Validate a sender-constrained access token at a resource server.

Verifies that the token’s cnf claim matches the presented proof (DPoP proof JKT or mTLS certificate thumbprint).

Source

pub fn validate_authorization_details( &self, authorization_details: &[AuthorizationDetail], ) -> Result<()>

Validate a Rich Authorization Request (RFC 9396) authorization_details parameter.

Trait Implementations§

Source§

impl Clone for FapiManager

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FapiManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more