oxide_auth_async/
primitives.rs

1//! Async versions of all primitives traits.
2use async_trait::async_trait;
3use oxide_auth::primitives::{grant::Grant, scope::Scope};
4use oxide_auth::primitives::issuer::{IssuedToken, RefreshedToken};
5use oxide_auth::primitives::{
6    authorizer, registrar, issuer,
7    registrar::{ClientUrl, BoundClient, RegistrarError, PreGrant},
8};
9
10#[async_trait]
11pub trait Authorizer {
12    async fn authorize(&mut self, _: Grant) -> Result<String, ()>;
13
14    async fn extract(&mut self, _: &str) -> Result<Option<Grant>, ()>;
15}
16
17#[async_trait]
18impl<T> Authorizer for T
19where
20    T: authorizer::Authorizer + Send + ?Sized,
21{
22    async fn authorize(&mut self, grant: Grant) -> Result<String, ()> {
23        authorizer::Authorizer::authorize(self, grant)
24    }
25
26    async fn extract(&mut self, token: &str) -> Result<Option<Grant>, ()> {
27        authorizer::Authorizer::extract(self, token)
28    }
29}
30
31#[async_trait]
32pub trait Issuer {
33    async fn issue(&mut self, _: Grant) -> Result<IssuedToken, ()>;
34
35    async fn refresh(&mut self, _: &str, _: Grant) -> Result<RefreshedToken, ()>;
36
37    async fn recover_token(&mut self, _: &str) -> Result<Option<Grant>, ()>;
38
39    async fn recover_refresh(&mut self, _: &str) -> Result<Option<Grant>, ()>;
40}
41
42#[async_trait]
43impl<T> Issuer for T
44where
45    T: issuer::Issuer + Send + ?Sized,
46{
47    async fn issue(&mut self, grant: Grant) -> Result<IssuedToken, ()> {
48        issuer::Issuer::issue(self, grant)
49    }
50
51    async fn refresh(&mut self, token: &str, grant: Grant) -> Result<RefreshedToken, ()> {
52        issuer::Issuer::refresh(self, token, grant)
53    }
54
55    async fn recover_token(&mut self, token: &str) -> Result<Option<Grant>, ()> {
56        issuer::Issuer::recover_token(self, token)
57    }
58
59    async fn recover_refresh(&mut self, token: &str) -> Result<Option<Grant>, ()> {
60        issuer::Issuer::recover_refresh(self, token)
61    }
62}
63
64#[async_trait]
65pub trait Registrar {
66    async fn bound_redirect<'a>(&self, bound: ClientUrl<'a>) -> Result<BoundClient<'a>, RegistrarError>;
67
68    async fn negotiate<'a>(
69        &self, client: BoundClient<'a>, scope: Option<Scope>,
70    ) -> Result<PreGrant, RegistrarError>;
71
72    async fn check(&self, client_id: &str, passphrase: Option<&[u8]>) -> Result<(), RegistrarError>;
73}
74
75#[async_trait]
76impl<T> Registrar for T
77where
78    T: registrar::Registrar + Send + Sync + ?Sized,
79{
80    async fn bound_redirect<'a>(&self, bound: ClientUrl<'a>) -> Result<BoundClient<'a>, RegistrarError> {
81        registrar::Registrar::bound_redirect(self, bound)
82    }
83
84    async fn negotiate<'a>(
85        &self, client: BoundClient<'a>, scope: Option<Scope>,
86    ) -> Result<PreGrant, RegistrarError> {
87        registrar::Registrar::negotiate(self, client, scope)
88    }
89
90    async fn check(&self, client_id: &str, passphrase: Option<&[u8]>) -> Result<(), RegistrarError> {
91        registrar::Registrar::check(self, client_id, passphrase)
92    }
93}