tako_rs_plugins/middleware/jwt_auth/
revocation.rs1use std::future::Future;
4use std::pin::Pin;
5use std::sync::Arc;
6
7use scc::HashSet as SccHashSet;
8
9pub trait RevocationList: Send + Sync + 'static {
12 fn is_revoked(&self, jti: &str) -> bool;
13}
14
15#[derive(Default, Clone)]
17pub struct InMemoryRevocationList {
18 inner: Arc<SccHashSet<String>>,
19}
20
21impl InMemoryRevocationList {
22 pub fn new() -> Self {
23 Self::default()
24 }
25
26 pub fn revoke(&self, jti: impl Into<String>) {
27 let _ = self.inner.insert_sync(jti.into());
28 }
29
30 pub fn unrevoke(&self, jti: &str) {
31 let _ = self.inner.remove_sync(jti);
32 }
33}
34
35impl RevocationList for InMemoryRevocationList {
36 fn is_revoked(&self, jti: &str) -> bool {
37 self.inner.contains_sync(jti)
38 }
39}
40
41pub type IntrospectionFn =
44 Arc<dyn Fn(&str) -> Pin<Box<dyn Future<Output = bool> + Send + 'static>> + Send + Sync + 'static>;
45
46pub type JtiExtractorFn<C> = Arc<dyn Fn(&C) -> Option<String> + Send + Sync + 'static>;
49
50pub type RevocationCheck<C> = (Arc<dyn RevocationList>, JtiExtractorFn<C>);