hive_client/client/authentication/
error.rs

1use crate::client::authentication::ChallengeRequest;
2use aws_cognito_srp::SrpError;
3use aws_sdk_cognitoidentityprovider::error::SdkError;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7#[error(transparent)]
8#[non_exhaustive]
9/// Errors that can occur while trying to communicate with the Hive Authentication servers.
10pub enum AuthenticationError {
11    #[error("The session token was not found in the response")]
12    /// No Access Token was issued in the response from the Hive authentication servers.
13    InvalidAccessToken,
14
15    #[error("The presented challenge is not supported. Challenge was: {0}")]
16    /// The challenge presented by the Hive authentication servers is not supported by this crate.
17    UnsupportedChallenge(String),
18
19    #[error(transparent)]
20    /// The request to begin the authentication flow failed.
21    LoginFailed(
22        #[from]
23        SdkError<aws_sdk_cognitoidentityprovider::operation::initiate_auth::InitiateAuthError>,
24    ),
25
26    #[error(transparent)]
27    /// The request to respond to a challenge during the authentication flow failed.
28    ChallengeFailed(
29        #[from]
30        SdkError<aws_sdk_cognitoidentityprovider::operation::respond_to_auth_challenge::RespondToAuthChallengeError>,
31    ),
32
33    #[error("The challenge was not handled correctly")]
34    /// A parameter which was expected to be present in the challenge was not found.
35    MissingChallengeParameter(String),
36
37    #[error("An error occurred while trying to authenticate the user")]
38    /// An error occured while trying to complete the [Secure Remote Password (SRP)](https://github.com/ryanmab/aws-cognito-srp) authentication challenges.
39    SrpFailed(
40        #[from]
41        SrpError,
42    ),
43
44    #[error("A challenge was requested")]
45    /// A challenge was requested by the Hive authentication servers which requires manual intervention.
46    ///
47    /// For example, a SMS MFA code was sent to the user's phone number.
48    NextChallenge(ChallengeRequest),
49
50    /// The request to confirm the device (to make it a [`crate::authentication::TrustedDevice`]) failed.
51    DeviceConfirmationError(
52        #[from]
53        DeviceConfirmationError
54    ),
55
56    #[error("There is currently no valid authentication in progress")]
57    /// There is no authentication flow currently in progress, and the user is not logged in.
58    NoAuthenticationInProgress,
59}
60
61#[derive(Error, Debug)]
62#[error(transparent)]
63/// Errors that can occur while trying to refresh an existing authentication.
64pub enum RefreshError {
65    #[error("The request to refresh the authentication tokens failed as the access token could not be validated")]
66    /// The request to refresh the authentication tokens failed as the access token could
67    /// not be validated.
68    InvalidAccessToken,
69
70    #[error("The request to refresh the authentication tokens failed")]
71    /// The request to refresh the authentication tokens failed.
72    RequestFailed(String),
73
74    #[error("There is currently no valid authentication in progress")]
75    /// There is no authentication flow currently in progress, and the user is not logged in.
76    NotLoggedIn,
77}
78
79#[derive(Error, Debug)]
80#[error(transparent)]
81/// Errors that can occur while trying to confirm a device in order to
82/// make it a [`crate::authentication::TrustedDevice`].
83pub enum DeviceConfirmationError {
84    #[error(transparent)]
85    /// The request to confirm the device failed.
86    ConfirmationFailed(
87        #[from]
88        SdkError<aws_sdk_cognitoidentityprovider::operation::confirm_device::ConfirmDeviceError>,
89    ),
90
91    #[error(transparent)]
92    /// The request to update the device status failed.
93    StatusUpdateFailed(
94        #[from]
95        SdkError<aws_sdk_cognitoidentityprovider::operation::update_device_status::UpdateDeviceStatusError>,
96    ),
97
98    #[error("The device being confirmed is already tracked")]
99    /// The device being confirmed is already tracked, meaning no confirmation is needed.
100    DeviceAlreadyTracked,
101}