use serde::{Deserialize, Serialize};
use std::{borrow::Cow, fmt::Debug};
use time::OffsetDateTime;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AccessToken(Cow<'static, str>);
impl AccessToken {
pub fn new<T>(access_token: T) -> Self
where
T: Into<Cow<'static, str>>,
{
Self(access_token.into())
}
pub fn secret(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone)]
pub struct TokenResponse {
pub token: AccessToken,
pub expires_on: OffsetDateTime,
}
impl TokenResponse {
pub fn new(token: AccessToken, expires_on: OffsetDateTime) -> Self {
Self { token, expires_on }
}
}
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
pub trait TokenCredential: Send + Sync {
async fn get_token(&self, resource: &str) -> crate::Result<TokenResponse>;
}