AuthError

Enum AuthError 

Source
pub enum AuthError {
Show 43 variants Configuration { message: String, source: Option<Box<dyn Error + Send + Sync>>, help: Option<String>, docs_url: Option<String>, suggested_fix: Option<String>, }, AuthMethod { method: String, message: String, help: Option<String>, docs_url: Option<String>, suggested_fix: Option<String>, }, Token(TokenError), Permission(PermissionError), Storage(StorageError), Network(Error), Json(Error), Jwt(Error), Yaml(Error), Toml(Error), Io(Error), Cli(String), SystemTime(SystemTimeError), RateLimit { message: String, }, TooManyConcurrentSessions, Mfa(MfaError), DeviceFlow(DeviceFlowError), OAuthProvider(OAuthProviderError), PasswordVerification(String), PasswordHashing(String), UserNotFound, InvalidInput(String), HardwareToken(String), BackupCodeVerification(String), BackupCodeHashing(String), InvalidSecret, UserProfile { message: String, }, InvalidCredential { credential_type: String, message: String, }, Timeout { timeout_seconds: u64, }, ProviderNotConfigured { provider: String, }, Crypto { message: String, }, Validation { message: String, }, Internal { message: String, }, InvalidRequest(String), StepUpRequired { current_level: String, required_level: String, step_up_url: String, }, SessionError(String), Unauthorized(String), TokenGeneration(String), InvalidToken(String), UnsupportedProvider(String), NetworkError(String), ParseError(String), ConfigurationError(String),
}
Expand description

Comprehensive error type covering all authentication and authorization failures.

AuthError provides detailed error information for all aspects of the authentication framework, from configuration issues to runtime failures. Each error variant includes contextual information to aid in debugging and provide appropriate user feedback.

This enhanced error type provides:

  • Actionable error messages with specific suggestions for fixes
  • Documentation links to relevant guides and troubleshooting
  • Contextual help that guides users to solutions
  • Security-aware messaging that doesnโ€™t leak sensitive information

ยงError Categories

ยงConfiguration Errors

Errors that occur during framework setup and configuration validation.

ยงAuthentication Errors

Errors related to credential validation and authentication method execution.

ยงAuthorization Errors

Errors related to permission checking and access control.

ยงToken Errors

JWT token creation, validation, expiration, and lifecycle issues.

ยงStorage Errors

Database connectivity, query failures, and data persistence issues.

ยงNetwork Errors

External service communication, timeouts, and connectivity problems.

ยงCryptographic Errors

Encryption, decryption, signing, and other security operation failures.

ยงEnhanced Error Handling

use auth_framework::AuthError;

// Enhanced error handling with contextual help
match auth_result {
    Err(AuthError::Configuration { message, help, docs_url, .. }) => {
        eprintln!("โŒ Configuration Error: {}", message);
        if let Some(help) = help {
            eprintln!("๐Ÿ’ก Help: {}", help);
        }
        if let Some(docs) = docs_url {
            eprintln!("๐Ÿ“– See: {}", docs);
        }
    },
    Err(AuthError::InvalidCredential { credential_type, message, suggested_fix, .. }) => {
        eprintln!("๐Ÿ” Invalid {}: {}", credential_type, message);
        if let Some(fix) = suggested_fix {
            eprintln!("๐Ÿ”ง Suggested fix: {}", fix);
        }
    },
    // ... handle other error types
}

ยงSecurity Notes

Error messages are carefully crafted to:

  • Provide sufficient detail for debugging and monitoring
  • Avoid exposing sensitive information that could aid attackers
  • Enable security teams to identify potential threats
  • Support compliance and audit requirements
  • Guide users to secure solutions and best practices

Variantsยง

ยง

Configuration

Configuration validation and setup errors.

These errors occur when the authentication framework is misconfigured or when configuration validation fails during startup.

Fields

ยงmessage: String
ยงsource: Option<Box<dyn Error + Send + Sync>>
ยงhelp: Option<String>

Helpful guidance for fixing the issue

ยงdocs_url: Option<String>

Link to relevant documentation

ยงsuggested_fix: Option<String>

Specific fix suggestion with commands or code

ยง

AuthMethod

Authentication method execution errors.

These errors occur when a specific authentication method fails to execute properly, such as OAuth provider communication failures.

Fields

ยงmethod: String
ยงmessage: String
ยงhelp: Option<String>

Helpful guidance for fixing the issue

ยงdocs_url: Option<String>

Link to relevant documentation

ยงsuggested_fix: Option<String>

Specific fix suggestion

ยง

Token(TokenError)

Token-related errors

ยง

Permission(PermissionError)

Permission-related errors

ยง

Storage(StorageError)

Storage-related errors

ยง

Network(Error)

Network/HTTP errors

ยง

Json(Error)

JSON parsing errors

ยง

Jwt(Error)

JWT errors

ยง

Yaml(Error)

YAML parsing errors

ยง

Toml(Error)

TOML parsing errors

ยง

Io(Error)

IO errors

ยง

Cli(String)

CLI interaction errors

ยง

SystemTime(SystemTimeError)

System time errors

ยง

RateLimit

Rate limiting errors

Fields

ยงmessage: String
ยง

TooManyConcurrentSessions

Session-related errors

ยง

Mfa(MfaError)

MFA-related errors

ยง

DeviceFlow(DeviceFlowError)

Device flow errors

ยง

OAuthProvider(OAuthProviderError)

OAuth provider errors

ยง

PasswordVerification(String)

Password verification errors

ยง

PasswordHashing(String)

Password hashing errors

ยง

UserNotFound

User not found error

ยง

InvalidInput(String)

Invalid input error

ยง

HardwareToken(String)

Hardware token errors

ยง

BackupCodeVerification(String)

Backup code verification errors

ยง

BackupCodeHashing(String)

Backup code hashing errors

ยง

InvalidSecret

Invalid secret error

ยง

UserProfile

User profile errors

Fields

ยงmessage: String
ยง

InvalidCredential

Credential validation errors

Fields

ยงcredential_type: String
ยงmessage: String
ยง

Timeout

Authentication timeout

Fields

ยงtimeout_seconds: u64
ยง

ProviderNotConfigured

Provider configuration missing

Fields

ยงprovider: String
ยง

Crypto

Cryptography errors

Fields

ยงmessage: String
ยง

Validation

Validation errors

Fields

ยงmessage: String
ยง

Internal

Generic internal errors

Fields

ยงmessage: String
ยง

InvalidRequest(String)

Invalid request error

ยง

StepUpRequired

Step-up authentication required

Fields

ยงcurrent_level: String
ยงrequired_level: String
ยงstep_up_url: String
ยง

SessionError(String)

Session error

ยง

Unauthorized(String)

Unauthorized access

ยง

TokenGeneration(String)

Token generation error

ยง

InvalidToken(String)

Invalid token error

ยง

UnsupportedProvider(String)

Unsupported provider error

ยง

NetworkError(String)

Network error with custom message

ยง

ParseError(String)

Parse error with custom message

ยง

ConfigurationError(String)

Configuration error with custom message

Implementationsยง

Sourceยง

impl AuthError

Source

pub fn config(message: impl Into<String>) -> Self

Create a new configuration error

Source

pub fn config_with_help( message: impl Into<String>, help: impl Into<String>, suggested_fix: Option<String>, ) -> Self

Create a configuration error with helpful context

Source

pub fn jwt_secret_too_short(current_length: usize) -> Self

Create a JWT secret validation error with helpful guidance

Source

pub fn production_memory_storage() -> Self

Create a production environment error with guidance

Source

pub fn auth_method( method: impl Into<String>, message: impl Into<String>, ) -> Self

Create a new auth method error

Source

pub fn auth_method_with_help( method: impl Into<String>, message: impl Into<String>, help: impl Into<String>, suggested_fix: Option<String>, ) -> Self

Create an auth method error with helpful context

Source

pub fn rate_limit(message: impl Into<String>) -> Self

Create a new rate limit error

Source

pub fn crypto(message: impl Into<String>) -> Self

Create a new crypto error

Source

pub fn validation(message: impl Into<String>) -> Self

Create a new validation error

Source

pub fn internal(message: impl Into<String>) -> Self

Create a new internal error

Source

pub fn authorization(message: impl Into<String>) -> Self

Create an authorization error

Source

pub fn access_denied(message: impl Into<String>) -> Self

Create an access denied error

Source

pub fn token(message: impl Into<String>) -> Self

Create a token error

Source

pub fn device_flow(error: DeviceFlowError) -> Self

Create a device flow error

Source

pub fn oauth_provider(error: OAuthProviderError) -> Self

Create an OAuth provider error

Source

pub fn user_profile(message: impl Into<String>) -> Self

Create a user profile error

Source

pub fn invalid_credential( credential_type: impl Into<String>, message: impl Into<String>, ) -> Self

Create an invalid credential error

Source

pub fn timeout(timeout_seconds: u64) -> Self

Create a timeout error

Source

pub fn provider_not_configured(provider: impl Into<String>) -> Self

Create a provider not configured error

Source

pub fn rate_limited(message: impl Into<String>) -> Self

Create a rate limited error

Source

pub fn configuration(message: impl Into<String>) -> Self

Create a configuration error

Trait Implementationsยง

Sourceยง

impl Debug for AuthError

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Display for AuthError

Sourceยง

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Error for AuthError

Sourceยง

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 ยท Sourceยง

fn description(&self) -> &str

๐Ÿ‘ŽDeprecated since 1.42.0: use the Display impl or to_string()
1.0.0 ยท Sourceยง

fn cause(&self) -> Option<&dyn Error>

๐Ÿ‘ŽDeprecated since 1.33.0: replaced by Error::source, which can support downcasting
Sourceยง

fn provide<'a>(&'a self, request: &mut Request<'a>)

๐Ÿ”ฌThis is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Sourceยง

impl From<AuthError> for ApiResponse<()>

Convert AuthError to API response

Sourceยง

fn from(error: AuthError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Box<dyn Error>> for AuthError

Sourceยง

fn from(error: Box<dyn Error>) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Box<dyn Error + Send + Sync>> for AuthError

Sourceยง

fn from(error: Box<dyn Error + Send + Sync>) -> Self

Converts to this type from the input type.
Sourceยง

impl From<DeviceFlowError> for AuthError

Sourceยง

fn from(source: DeviceFlowError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Error> for AuthError

Sourceยง

fn from(source: Error) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Error> for AuthError

Sourceยง

fn from(source: Error) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Error> for AuthError

Sourceยง

fn from(source: Error) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Error> for AuthError

Sourceยง

fn from(source: Error) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Error> for AuthError

Sourceยง

fn from(source: Error) -> Self

Converts to this type from the input type.
Sourceยง

impl From<Error> for AuthError

Sourceยง

fn from(source: Error) -> Self

Converts to this type from the input type.
Sourceยง

impl From<MfaError> for AuthError

Sourceยง

fn from(source: MfaError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<OAuthProviderError> for AuthError

Sourceยง

fn from(source: OAuthProviderError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<PermissionError> for AuthError

Sourceยง

fn from(source: PermissionError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<StorageError> for AuthError

Sourceยง

fn from(source: StorageError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<SystemTimeError> for AuthError

Sourceยง

fn from(source: SystemTimeError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<TokenError> for AuthError

Sourceยง

fn from(source: TokenError) -> Self

Converts to this type from the input type.

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Sourceยง

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Sourceยง

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Sourceยง

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

impl<T> PolicyExt for T
where T: ?Sized,

Sourceยง

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Sourceยง

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
Sourceยง

impl<T> ToString for T
where T: Display + ?Sized,

Sourceยง

fn to_string(&self) -> String

Converts the given value to a String. Read more
Sourceยง

impl<T> ToStringFallible for T
where T: Display,

Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,