mod implementation;
mod no_dpop;
mod sealed;
use std::sync::Arc;
use http::{Method, Uri};
pub use implementation::{
DPoP, DPoPBuilder, ResourceDPoP, ResourceDPoPBuilder, hash_access_token_for_dpop,
normalize_uri_for_dpop,
};
pub use no_dpop::{DPoPNotConfigured, NoDPoP};
use crate::{
error::Error,
platform::{MaybeSendBoxFuture, MaybeSendSync},
secrets::SecretString,
};
pub trait AuthorizationServerDPoP: sealed::Sealed + MaybeSendSync {
fn update_nonce(&self, nonce: String);
fn get_current_thumbprint(&self) -> MaybeSendBoxFuture<'_, Option<String>>;
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
dpop_jkt: Option<&'a str>,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>>;
fn to_resource_server_dpop(&self) -> Arc<dyn ResourceServerDPoP>;
}
pub trait ResourceServerDPoP: sealed::Sealed + MaybeSendSync {
fn update_nonce(&self, uri: &Uri, nonce: String);
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
access_token: &'a SecretString,
dpop_jkt: &'a str,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>>;
}
impl<T: AuthorizationServerDPoP + ?Sized> AuthorizationServerDPoP for &T {
fn update_nonce(&self, nonce: String) {
(**self).update_nonce(nonce);
}
fn get_current_thumbprint(&self) -> MaybeSendBoxFuture<'_, Option<String>> {
(**self).get_current_thumbprint()
}
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
dpop_jkt: Option<&'a str>,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>> {
(**self).proof(method, uri, dpop_jkt)
}
fn to_resource_server_dpop(&self) -> Arc<dyn ResourceServerDPoP> {
(**self).to_resource_server_dpop()
}
}
impl<T: AuthorizationServerDPoP + ?Sized> AuthorizationServerDPoP for Box<T> {
fn update_nonce(&self, nonce: String) {
(**self).update_nonce(nonce);
}
fn get_current_thumbprint(&self) -> MaybeSendBoxFuture<'_, Option<String>> {
(**self).get_current_thumbprint()
}
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
dpop_jkt: Option<&'a str>,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>> {
(**self).proof(method, uri, dpop_jkt)
}
fn to_resource_server_dpop(&self) -> Arc<dyn ResourceServerDPoP> {
(**self).to_resource_server_dpop()
}
}
impl<T: AuthorizationServerDPoP + ?Sized> AuthorizationServerDPoP for Arc<T> {
fn update_nonce(&self, nonce: String) {
(**self).update_nonce(nonce);
}
fn get_current_thumbprint(&self) -> MaybeSendBoxFuture<'_, Option<String>> {
(**self).get_current_thumbprint()
}
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
dpop_jkt: Option<&'a str>,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>> {
(**self).proof(method, uri, dpop_jkt)
}
fn to_resource_server_dpop(&self) -> Arc<dyn ResourceServerDPoP> {
(**self).to_resource_server_dpop()
}
}
impl<T: ResourceServerDPoP + ?Sized> ResourceServerDPoP for &T {
fn update_nonce(&self, uri: &Uri, nonce: String) {
(**self).update_nonce(uri, nonce);
}
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
access_token: &'a SecretString,
dpop_jkt: &'a str,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>> {
(**self).proof(method, uri, access_token, dpop_jkt)
}
}
impl<T: ResourceServerDPoP + ?Sized> ResourceServerDPoP for Box<T> {
fn update_nonce(&self, uri: &Uri, nonce: String) {
(**self).update_nonce(uri, nonce);
}
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
access_token: &'a SecretString,
dpop_jkt: &'a str,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>> {
(**self).proof(method, uri, access_token, dpop_jkt)
}
}
impl<T: ResourceServerDPoP + ?Sized> ResourceServerDPoP for Arc<T> {
fn update_nonce(&self, uri: &Uri, nonce: String) {
(**self).update_nonce(uri, nonce);
}
fn proof<'a>(
&'a self,
method: &'a Method,
uri: &'a Uri,
access_token: &'a SecretString,
dpop_jkt: &'a str,
) -> MaybeSendBoxFuture<'a, Result<Option<SecretString>, Error>> {
(**self).proof(method, uri, access_token, dpop_jkt)
}
}