1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::identity::{DecodedJwt, ForceTokenRefresh};
use async_trait::async_trait;
use graph_error::AuthExecutionError;

pub trait AsBearer<RHS = Self> {
    fn as_bearer(&self) -> String;
}

impl AsBearer for String {
    fn as_bearer(&self) -> String {
        self.clone()
    }
}

impl AsBearer for &str {
    fn as_bearer(&self) -> String {
        self.to_string()
    }
}

#[async_trait]
pub trait TokenCache {
    type Token: AsBearer;

    fn get_token_silent(&mut self) -> Result<Self::Token, AuthExecutionError>;

    async fn get_token_silent_async(&mut self) -> Result<Self::Token, AuthExecutionError>;

    fn with_force_token_refresh(&mut self, force_token_refresh: ForceTokenRefresh);

    fn decoded_jwt(&self) -> Option<&DecodedJwt> {
        None
    }
}