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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
use axum::{
http::{self, StatusCode},
response::IntoResponse,
};
use openidconnect::{core::CoreErrorResponseType, ClaimsVerificationError, StandardErrorResponse};
use tracing::error;
type UserInfoError = openidconnect::UserInfoError<openidconnect::reqwest::Error<reqwest::Error>>;
type RequestTokenError = openidconnect::RequestTokenError<
openidconnect::reqwest::Error<reqwest::Error>,
StandardErrorResponse<CoreErrorResponseType>,
>;
#[derive(thiserror::Error, Debug)]
pub enum BridgeError {
#[error("Invalid request: {0}")]
InvalidRequest(String),
#[error("Requesting token failed")]
OpenidRequestTokenError(#[from] RequestTokenError),
#[error("Requesting user info failed")]
OpenidUserInfoError(#[from] UserInfoError),
#[error("Failed to configure OpenId request")]
OpenIdConfigurationError(#[from] openidconnect::ConfigurationError),
#[error("Unexpected authorization error")]
UnexpectedInvalidAuthorization(#[from] ClaimsVerificationError),
#[error("User is not logged in")]
NotLoggedIn,
#[error("Authentication error")]
SigningFailed(#[from] openidconnect::SigningError),
#[error("Database error")]
SqlxError(#[from] sqlx::Error),
#[error("Uuid parse failed")]
UuidError(#[from] uuid::Error),
#[error("Internal server error: {0}")]
Internal(String),
#[error("Duration out of range")]
DurationOutOfRange(#[from] time::OutOfRangeError),
}
impl BridgeError {
pub fn as_rejection(&self) -> (http::StatusCode, String) {
match self {
BridgeError::OpenidRequestTokenError(_) => {
(StatusCode::UNAUTHORIZED, format!("Error fetching token"))
}
_ => (StatusCode::INTERNAL_SERVER_ERROR, format!("Error: {self}")),
}
}
}
impl IntoResponse for BridgeError {
fn into_response(self) -> axum::response::Response {
error!("Error occurred: {self:?}");
self.as_rejection().into_response()
}
}
|