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
impl FapiManager
Sourcepub 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
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
Sourcepub fn with_rate_limiter(self, limiter: Arc<DistributedRateLimiter>) -> Self
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.
Like validate_authorization_request, counting the request against the
caller address peer first and, once the request object is valid, against its client.
Validate FAPI 2.0 authorization request
Sourcepub async fn authenticate_client_jwt(
&self,
client_assertion: &str,
) -> Result<String>
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.
Sourcepub async fn validate_token_request(
&self,
client_assertion: Option<&str>,
client_cert: Option<&str>,
dpop_proof: Option<&str>,
_authorization_code: &str,
) -> Result<String>
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
Sourcepub 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>
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).
Generate FAPI 2.0 authorization response (JARM)
Sourcepub 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>
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
Sourcepub 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>
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
Sourcepub async fn get_session(&self, session_id: &str) -> Result<Option<FapiSession>>
pub async fn get_session(&self, session_id: &str) -> Result<Option<FapiSession>>
Get FAPI session
Sourcepub async fn validate_session(&self, session_id: &str) -> Result<FapiSession>
pub async fn validate_session(&self, session_id: &str) -> Result<FapiSession>
Validate FAPI session
Sourcepub async fn remove_session(&self, session_id: &str) -> Result<()>
pub async fn remove_session(&self, session_id: &str) -> Result<()>
Remove FAPI session
Sourcepub async fn audit_log(&self, event: &str, details: &Value) -> Result<()>
pub async fn audit_log(&self, event: &str, details: &Value) -> Result<()>
Audit log entry for FAPI compliance
Sourcepub fn check_compliance(&self) -> Vec<FapiComplianceViolation>
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.
Sourcepub fn is_compliant(&self) -> bool
pub fn is_compliant(&self) -> bool
Returns true if the configuration is fully FAPI 2.0 compliant (no critical violations).
Sourcepub 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>
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).
Validate a Rich Authorization Request (RFC 9396) authorization_details parameter.
Trait Implementations§
Source§impl Clone for FapiManager
impl Clone for FapiManager
Auto Trait Implementations§
impl !RefUnwindSafe for FapiManager
impl !UnwindSafe for FapiManager
impl Freeze for FapiManager
impl Send for FapiManager
impl Sync for FapiManager
impl Unpin for FapiManager
impl UnsafeUnpin for FapiManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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