use async_trait::async_trait;
use crate::error::Result;
#[async_trait]
pub trait AccessTokenProvider: Send + Sync + 'static {
async fn access_token(&self) -> Result<String>;
async fn invalidate(&self, rejected: &str);
}
#[derive(Clone)]
pub struct StaticToken(String);
impl StaticToken {
pub fn new(token: impl Into<String>) -> Self {
Self(token.into())
}
}
impl std::fmt::Debug for StaticToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("StaticToken(..)")
}
}
#[async_trait]
impl AccessTokenProvider for StaticToken {
async fn access_token(&self) -> Result<String> {
Ok(self.0.clone())
}
async fn invalidate(&self, _rejected: &str) {}
}