use azure_core::credentials::AccessToken;
use std::{fmt::Display, sync::Arc};
use crate::{
authorization::service_bus_token_credential::ServiceBusTokenCredential,
constants::{JSON_WEB_TOKEN_TYPE, SAS_TOKEN_TYPE},
};
#[derive(Debug)]
pub(crate) enum TokenType {
SharedAccessToken {
credential: Arc<ServiceBusTokenCredential>,
},
JsonWebToken {
credential: Arc<ServiceBusTokenCredential>,
cached_token: Option<AccessToken>,
},
}
impl TokenType {
pub(crate) fn entity_type(&self) -> &str {
match self {
TokenType::SharedAccessToken { .. } => SAS_TOKEN_TYPE,
TokenType::JsonWebToken { .. } => JSON_WEB_TOKEN_TYPE,
}
}
}
impl Display for TokenType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TokenType::SharedAccessToken { .. } => write!(f, "{}", SAS_TOKEN_TYPE),
TokenType::JsonWebToken { .. } => write!(f, "{}", JSON_WEB_TOKEN_TYPE),
}
}
}