use crate::client::authentication::ChallengeRequest;
use aws_cognito_srp::SrpError;
use aws_sdk_cognitoidentityprovider::error::SdkError;
use thiserror::Error;
#[derive(Error, Debug)]
#[error(transparent)]
#[non_exhaustive]
pub enum AuthenticationError {
#[error("The session token was not found in the response")]
InvalidAccessToken,
#[error("The presented challenge is not supported. Challenge was: {0}")]
UnsupportedChallenge(String),
#[error(transparent)]
LoginFailed(
#[from]
SdkError<aws_sdk_cognitoidentityprovider::operation::initiate_auth::InitiateAuthError>,
),
#[error(transparent)]
ChallengeFailed(
#[from]
SdkError<aws_sdk_cognitoidentityprovider::operation::respond_to_auth_challenge::RespondToAuthChallengeError>,
),
#[error("The challenge was not handled correctly")]
MissingChallengeParameter(String),
#[error("An error occurred while trying to authenticate the user")]
SrpFailed(
#[from]
SrpError,
),
#[error("A challenge was requested")]
NextChallenge(ChallengeRequest),
DeviceConfirmationError(
#[from]
DeviceConfirmationError
),
#[error("There is currently no valid authentication in progress")]
NoAuthenticationInProgress,
}
#[derive(Error, Debug)]
#[error(transparent)]
pub enum RefreshError {
#[error(
"The request to refresh the authentication tokens failed as the access token could not be validated"
)]
InvalidAccessToken,
#[error("The request to refresh the authentication tokens failed")]
RequestFailed(String),
#[error("There is currently no valid authentication in progress")]
NotLoggedIn,
}
#[derive(Error, Debug)]
#[error(transparent)]
pub enum DeviceConfirmationError {
#[error(transparent)]
ConfirmationFailed(
#[from]
SdkError<aws_sdk_cognitoidentityprovider::operation::confirm_device::ConfirmDeviceError>,
),
#[error(transparent)]
StatusUpdateFailed(
#[from]
SdkError<aws_sdk_cognitoidentityprovider::operation::update_device_status::UpdateDeviceStatusError>,
),
#[error("The device being confirmed is already tracked")]
DeviceAlreadyTracked,
}