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
#[derive(thiserror::Error, Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum RequestError {
    #[error("The provided Uri was invalid")]
    InvalidUri,

    #[error(transparent)]
    HTTP(#[from] http::Error),
}

#[derive(thiserror::Error, Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum TokenDataError {
    #[error("No JWKs provided to decode token")]
    NoJWKs,

    #[error(transparent)]
    JWTDecode(#[from] jsonwebtoken::errors::Error),
}

#[derive(thiserror::Error, Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum OidcValidationError {
    #[error("Nonce doesn't match initially provided nonce")]
    NonceMismatch,

    #[error("Provider did not contain a userinfo endpoint")]
    NoUserEndpoint,

    #[error("Sub from user data doesn't match sub from token data")]
    UserMismatch,

    #[error("Could not decode user info as utf8")]
    UserInfoDecode,

    #[error("Could not deserialize user info")]
    UserinfoDeserialize,

    #[error("State doesn't match initially provided state")]
    StateMismatch,
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
    /// Failed to authenticate and retrieve an oauth token, and were unable to
    /// deserialize a more exact reason from the error response
    #[error("{}", _0)]
    HttpStatus(http::StatusCode),
    /// Failed to de/serialize JSON
    #[error(transparent)]
    Json(#[from] serde_json::Error),
    /// An error occurred trying to create an HTTP request
    #[error(transparent)]
    Http(#[from] http::Error),

    #[error(transparent)]
    Request(#[from] RequestError),

    #[error(transparent)]
    TokenValidation(#[from] TokenDataError),

    #[error(transparent)]
    // Todo: Better name
    OidcValidation(#[from] OidcValidationError),
}