1use async_trait::async_trait;
2use dyn_clone::DynClone;
3use graph_error::AuthExecutionResult;
45#[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
6pub enum ForceTokenRefresh {
7/// Always use the token cache first to when returning tokens.
8 /// Expired tokens will still cause an authorization request to
9 /// be called.
10#[default]
11Never,
12/// ForceRefreshToken::Once will cause only the next authorization request
13 /// to ignore any tokens in cache and request a new token. Authorization
14 /// requests after this are treated as ForceRefreshToken::Never
15Once,
16/// Always make an authorization request regardless of any tokens in cache.
17Always,
18}
1920dyn_clone::clone_trait_object!(ClientApplication);
2122#[async_trait]
23pub trait ClientApplication: DynClone + Send + Sync {
24fn get_token_silent(&mut self) -> AuthExecutionResult<String>;
2526async fn get_token_silent_async(&mut self) -> AuthExecutionResult<String>;
2728fn with_force_token_refresh(&mut self, force_token_refresh: ForceTokenRefresh);
29}
3031#[async_trait]
32impl ClientApplication for String {
33fn get_token_silent(&mut self) -> AuthExecutionResult<String> {
34Ok(self.clone())
35 }
3637async fn get_token_silent_async(&mut self) -> AuthExecutionResult<String> {
38Ok(self.clone())
39 }
4041fn with_force_token_refresh(&mut self, _force_token_refresh: ForceTokenRefresh) {}
42}