fastauth_plugin_passkey/
error.rs1use fastauth_core::plugin_prelude::*;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum PasskeyError {
8 ChallengeNotFound,
11 NotAllowed,
14 FailedToVerifyRegistration,
17 UnknownCredential,
19 PasskeyNotFound,
21 AuthenticationFailed,
23 InvalidAssertion,
26 OriginNotConfigured,
28}
29
30impl PasskeyError {
31 const fn parts(self) -> (StatusCode, &'static str, &'static str) {
32 match self {
33 Self::ChallengeNotFound => (
34 StatusCode::BAD_REQUEST,
35 "CHALLENGE_NOT_FOUND",
36 "Challenge not found",
37 ),
38 Self::NotAllowed => (
39 StatusCode::UNAUTHORIZED,
40 "YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY",
41 "You are not allowed to register this passkey",
42 ),
43 Self::FailedToVerifyRegistration => (
44 StatusCode::BAD_REQUEST,
45 "FAILED_TO_VERIFY_REGISTRATION",
46 "Failed to verify registration",
47 ),
48 Self::UnknownCredential => (
49 StatusCode::UNAUTHORIZED,
50 "PASSKEY_NOT_FOUND",
51 "Passkey not found",
52 ),
53 Self::PasskeyNotFound => (
54 StatusCode::NOT_FOUND,
55 "PASSKEY_NOT_FOUND",
56 "Passkey not found",
57 ),
58 Self::AuthenticationFailed => (
59 StatusCode::UNAUTHORIZED,
60 "AUTHENTICATION_FAILED",
61 "Authentication failed",
62 ),
63 Self::InvalidAssertion => (
64 StatusCode::BAD_REQUEST,
65 "AUTHENTICATION_FAILED",
66 "Authentication failed",
67 ),
68 Self::OriginNotConfigured => (
69 StatusCode::INTERNAL_SERVER_ERROR,
70 "ORIGIN_NOT_CONFIGURED",
71 "Passkey origin is not configured. Set the passkey plugin's `rp_id` and `origin` \
72 to match `base_url`.",
73 ),
74 }
75 }
76
77 pub const fn code(self) -> &'static str {
79 self.parts().1
80 }
81}
82
83impl From<PasskeyError> for AuthError {
84 fn from(err: PasskeyError) -> Self {
85 let (status, code, message) = err.parts();
86 AuthError::new(status, code, message)
87 }
88}
89
90impl ErrorCodes for PasskeyError {
91 const CODES: &'static [&'static str] = &[
92 Self::ChallengeNotFound.code(),
93 Self::NotAllowed.code(),
94 Self::FailedToVerifyRegistration.code(),
95 Self::PasskeyNotFound.code(),
96 Self::AuthenticationFailed.code(),
97 Self::OriginNotConfigured.code(),
98 ];
99}