use std::future::Future;
use crate::error::Error;
use crate::oauth::TokenResponse;
pub trait PasAuthPort: Send + Sync + 'static {
fn refresh(
&self,
refresh_token: &str,
) -> impl Future<Output = Result<TokenResponse, PasFailure>> + Send;
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum PasFailure {
Rejected { status: u16, detail: String },
ServerError { status: u16, detail: String },
Transport { detail: String },
}
impl PasFailure {
#[must_use]
pub fn into_legacy_error(self, operation: &'static str) -> Error {
match self {
Self::Rejected { status, detail } | Self::ServerError { status, detail } => {
Error::OAuth { operation, status: Some(status), detail }
}
Self::Transport { detail } => Error::OAuth { operation, status: None, detail },
}
}
}