pub struct PrivateKeyJwtManager { /* private fields */ }Expand description
Private Key JWT Manager
Implementations§
Source§impl PrivateKeyJwtManager
impl PrivateKeyJwtManager
Sourcepub fn new(jwt_validator: SecureJwtValidator) -> Self
pub fn new(jwt_validator: SecureJwtValidator) -> Self
Create a new Private Key JWT Manager
Sourcepub fn require_audiences(self, require: bool) -> Self
pub fn require_audiences(self, require: bool) -> Self
Make registration refuse a client that configures no expected audience.
Without an audience an assertion cannot be bound to this server, so a genuine assertion captured elsewhere could be presented here. It is off by default so that a patch release does not start refusing existing registrations; a registration without an audience logs a warning. Turn it on once every client has its token endpoint configured.
Sourcepub async fn register_client(&self, config: ClientJwtConfig) -> Result<()>
pub async fn register_client(&self, config: ClientJwtConfig) -> Result<()>
Register a client for private key JWT authentication
Registration fails unless the key is a well-formed public RSA / EC (P-256,
P-384) / Ed25519 JWK, no symmetric algorithm is allowed, and at least one allowed
algorithm fits the key. A client without an expected audience is accepted with a
warning unless require_audiences is on.
Sourcepub async fn authenticate_client(
&self,
client_assertion: &str,
) -> Result<JwtAuthResult>
pub async fn authenticate_client( &self, client_assertion: &str, ) -> Result<JwtAuthResult>
Authenticate a client using private key JWT
Returns Err only for input that is not an assertion at all (oversized, not a JWT).
An unknown client and an assertion that does not verify both return Ok with
authenticated == false and the same single message; a refusal after the signature has
verified (wrong audience, expired, replayed, …) names its reason.
Sourcepub fn create_client_assertion(
&self,
client_id: &str,
audience: &str,
signing_key: &[u8],
algorithm: Algorithm,
) -> Result<String>
pub fn create_client_assertion( &self, client_id: &str, audience: &str, signing_key: &[u8], algorithm: Algorithm, ) -> Result<String>
Create a client assertion JWT (for testing/client-side use).
§Key encoding by algorithm
- HS256/384/512:
signing_keyis the raw HMAC secret bytes (such an assertion is refused byauthenticate_client: symmetric algorithms cannot be registered). - RS256/384/512, PS256/384/512: a PEM-encoded RSA private key.
- ES256/384: a PEM-encoded EC private key.
- EdDSA: a PEM-encoded Ed25519 private key.
Sourcepub async fn cleanup_expired_jtis(&self)
pub async fn cleanup_expired_jtis(&self)
Drop the remembered JTIs whose assertions could no longer be accepted anyway. A JTI is
kept until its own deadline (exp plus the client’s clock skew), never for a fixed
interval, so cleanup cannot reopen a replay window.
Sourcepub fn with_cleanup_interval(self, interval: Duration) -> Self
pub fn with_cleanup_interval(self, interval: Duration) -> Self
Set the cleanup interval for JTI management
Sourcepub fn get_cleanup_interval(&self) -> Duration
pub fn get_cleanup_interval(&self) -> Duration
Get the current cleanup interval
Sourcepub fn update_cleanup_interval(&mut self, interval: Duration)
pub fn update_cleanup_interval(&mut self, interval: Duration)
Update the cleanup interval
Sourcepub fn revoke_jwt_token(&self, jti: &str) -> Result<()>
pub fn revoke_jwt_token(&self, jti: &str) -> Result<()>
Revoke a JWT by its JTI using the enhanced validator
Sourcepub fn is_jwt_token_revoked(&self, jti: &str) -> Result<bool>
pub fn is_jwt_token_revoked(&self, jti: &str) -> Result<bool>
Check if a JWT is revoked using the enhanced validator
Sourcepub async fn schedule_automatic_cleanup(&self)
pub async fn schedule_automatic_cleanup(&self)
Clean up expired JTIs, and revocation records older than the cleanup interval. The
interval is raised to the longest time an assertion of a registered client can stay
acceptable (max_jwt_lifetime + 2 * clock_skew), so a revoked jti is never forgotten
while an assertion carrying it could still be presented.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PrivateKeyJwtManager
impl !RefUnwindSafe for PrivateKeyJwtManager
impl !UnwindSafe for PrivateKeyJwtManager
impl Send for PrivateKeyJwtManager
impl Sync for PrivateKeyJwtManager
impl Unpin for PrivateKeyJwtManager
impl UnsafeUnpin for PrivateKeyJwtManager
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> 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