Skip to main content

tame_oidc/
errors.rs

1#[derive(thiserror::Error, Debug)]
2#[allow(clippy::upper_case_acronyms)]
3pub enum RequestError {
4    #[error("The provided Uri was invalid")]
5    InvalidUri,
6
7    #[error(transparent)]
8    HTTP(#[from] http::Error),
9}
10
11#[derive(thiserror::Error, Debug)]
12#[allow(clippy::upper_case_acronyms)]
13pub enum TokenDataError {
14    #[error("No JWKs provided to decode token")]
15    NoJWKs,
16
17    #[error(transparent)]
18    JWTDecode(#[from] jsonwebtoken::errors::Error),
19}
20
21#[derive(thiserror::Error, Debug)]
22#[allow(clippy::upper_case_acronyms)]
23pub enum OidcValidationError {
24    #[error("Nonce doesn't match initially provided nonce")]
25    NonceMismatch,
26
27    #[error("Provider did not contain a userinfo endpoint")]
28    NoUserEndpoint,
29
30    #[error("Sub from user data doesn't match sub from token data")]
31    UserMismatch,
32
33    #[error("Could not decode user info as utf8")]
34    UserInfoDecode,
35
36    #[error("Could not deserialize user info")]
37    UserinfoDeserialize,
38
39    #[error("State doesn't match initially provided state")]
40    StateMismatch,
41}
42
43#[derive(thiserror::Error, Debug)]
44pub enum Error {
45    /// Failed to authenticate and retrieve an oauth token, and were unable to
46    /// deserialize a more exact reason from the error response
47    #[error("{}", _0)]
48    HttpStatus(http::StatusCode),
49    /// Failed to de/serialize JSON
50    #[error(transparent)]
51    Json(#[from] serde_json::Error),
52    /// An error occurred trying to create an HTTP request
53    #[error(transparent)]
54    Http(#[from] http::Error),
55
56    #[error(transparent)]
57    Request(#[from] RequestError),
58
59    #[error(transparent)]
60    TokenValidation(#[from] TokenDataError),
61
62    #[error(transparent)]
63    // Todo: Better name
64    OidcValidation(#[from] OidcValidationError),
65}