mod implementation;
mod no_dpop;
use std::sync::Arc;
use http::{Method, Uri};
use crate::{
platform::{MaybeSend, MaybeSendSync},
secrets::SecretString,
};
pub use implementation::{
DPoP, DPoPBuilder, ResourceDPoP, ResourceDPoPBuilder, hash_access_token_for_dpop,
normalize_uri_for_dpop,
};
pub use no_dpop::{DPoPNotConfigured, NoDPoP};
pub trait AuthorizationServerDPoP: Clone + MaybeSendSync {
type Error: crate::Error;
type ResourceServerDPoP: ResourceServerDPoP;
fn update_nonce(&self, nonce: String);
fn get_current_thumbprint(&self) -> Option<String>;
fn proof(
&self,
method: &Method,
uri: &Uri,
dpop_jkt: Option<&str>,
) -> impl Future<Output = Result<Option<SecretString>, Self::Error>> + MaybeSend;
fn to_resource_server_dpop(&self) -> Self::ResourceServerDPoP;
}
impl<D: AuthorizationServerDPoP> AuthorizationServerDPoP for Arc<D> {
type Error = D::Error;
type ResourceServerDPoP = D::ResourceServerDPoP;
fn update_nonce(&self, nonce: String) {
self.as_ref().update_nonce(nonce);
}
fn get_current_thumbprint(&self) -> Option<String> {
self.as_ref().get_current_thumbprint()
}
async fn proof(
&self,
method: &Method,
uri: &Uri,
dpop_jkt: Option<&str>,
) -> Result<Option<SecretString>, Self::Error> {
self.as_ref().proof(method, uri, dpop_jkt).await
}
fn to_resource_server_dpop(&self) -> Self::ResourceServerDPoP {
self.as_ref().to_resource_server_dpop()
}
}
pub trait ResourceServerDPoP: MaybeSendSync {
type Error: crate::Error;
fn update_nonce(&self, uri: &Uri, nonce: String);
fn proof(
&self,
method: &Method,
uri: &Uri,
access_token: &SecretString,
dpop_jkt: &str,
) -> impl Future<Output = Result<Option<SecretString>, Self::Error>> + MaybeSend;
}