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    AccessTokenNotValid,
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("The API call failed as the authentication could not be refreshed")]
57    /// The request to refresh the authentication tokens failed.
58    AuthenticationRefreshFailed,
59
60    #[error("There is currently no valid authentication in progress")]
61    /// There is no authentication flow currently in progress, and the user is not logged in.
62    NoAuthenticationInProgress,
63
64    #[error("Unable to continue with the authentication flow as the user is not logged in")]
65    /// No authentication flow has been started.
66    NotLoggedIn,
67
68    #[error("The device has already been confirmed")]
69    /// The device being confirmed is already trusted, meaning no confirmation is needed.
70    DeviceAlreadyTrusted,
71}
72
73#[derive(Error, Debug)]
74#[error(transparent)]
75/// Errors that can occur while trying to confirm a device in order to
76/// make it a [`crate::authentication::TrustedDevice`].
77pub enum DeviceConfirmationError {
78    #[error(transparent)]
79    /// The request to confirm the device failed.
80    ConfirmationFailed(
81        #[from]
82        SdkError<aws_sdk_cognitoidentityprovider::operation::confirm_device::ConfirmDeviceError>,
83    ),
84
85    #[error(transparent)]
86    /// The request to update the device status failed.
87    StatusUpdateFailed(
88        #[from]
89        SdkError<aws_sdk_cognitoidentityprovider::operation::update_device_status::UpdateDeviceStatusError>,
90    ),
91
92    #[error("The device being confirmed is already tracked")]
93    /// The device being confirmed is already tracked, meaning no confirmation is needed.
94    DeviceAlreadyTracked,
95}