mod implementation;
mod no_dpop;
use std::sync::Arc;
use http::{Method, Uri};
use crate::{
platform::{MaybeSend, MaybeSendSync},
secrets::SecretString,
token::AccessToken,
};
pub use implementation::{
DPoP, DPoPBuilder, ResourceDPoP, ResourceDPoPBuilder, hash_access_token_for_dpop,
normalize_uri_for_dpop,
};
pub use no_dpop::NoDPoP;
pub trait AuthorizationServerDPoP: Clone + MaybeSendSync {
type Error: crate::Error;
type ResourceServerDPoP: ResourceServerDPoP;
fn jwk_thumbprint(&self) -> Option<&str>;
fn update_nonce(&self, nonce: String);
fn proof(
&self,
method: &Method,
uri: &Uri,
) -> 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 jwk_thumbprint(&self) -> Option<&str> {
self.as_ref().jwk_thumbprint()
}
fn update_nonce(&self, nonce: String) {
self.as_ref().update_nonce(nonce);
}
async fn proof(&self, method: &Method, uri: &Uri) -> Result<Option<SecretString>, Self::Error> {
self.as_ref().proof(method, uri).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: &AccessToken,
) -> impl Future<Output = Result<Option<SecretString>, Self::Error>> + MaybeSend;
}