pub type AuthResult<T> = Result<T, AuthError>;
#[derive(Debug, thiserror::Error)]
pub enum AuthError {
#[error("Failed to parse an URL")]
ParseUrl(oauth2::url::ParseError),
#[error("There was a problem configuring the request: {0}")]
ConfigurationError(oauth2::ConfigurationError),
#[error("Error while requesting access token: {0}")]
RequestTokenError(String),
#[error("Microsoft did not provide a refresh token")]
NoRefreshToken,
#[error("{0}")]
Request(reqwest::Error),
#[error("XBoxLive auth did not return a user hash")]
NoXblUserHash,
#[error("User is missing entitlements")]
Unauthorized,
}
impl From<oauth2::url::ParseError> for AuthError {
fn from(err: oauth2::url::ParseError) -> Self {
Self::ParseUrl(err)
}
}
impl From<oauth2::ConfigurationError> for AuthError {
fn from(err: oauth2::ConfigurationError) -> Self {
Self::ConfigurationError(err)
}
}
impl From<reqwest::Error> for AuthError {
fn from(err: reqwest::Error) -> Self {
Self::Request(err)
}
}