1use std::fmt;
2
3#[derive(Debug, thiserror::Error)]
5pub enum AuthError {
6 #[error("Missing Authorization header")]
8 MissingToken,
9
10 #[error("Invalid token format: {0}")]
12 InvalidTokenFormat(String),
13
14 #[error("Token expired")]
16 TokenExpired,
17
18 #[error("Invalid signature")]
20 InvalidSignature,
21
22 #[error("Unsupported algorithm: {alg}")]
24 UnsupportedAlgorithm {
25 alg: String,
27 },
28
29 #[error("Unknown key ID: {kid}")]
31 UnknownKid {
32 kid: String,
34 },
35
36 #[error("JTI replay detected: {jti}")]
38 ReplayDetected {
39 jti: String,
41 },
42
43 #[error("Forbidden: insufficient scope for {operation} on {resource_type}")]
45 Forbidden {
46 resource_type: String,
48 operation: String,
50 },
51
52 #[error("JWKS fetch error: {0}")]
54 JwksFetchError(String),
55
56 #[error("Token validation error: {0}")]
58 ValidationError(String),
59
60 #[error("Internal auth error: {0}")]
62 InternalError(String),
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
67pub enum FhirOperation {
68 Read,
70 Search,
72 Create,
74 Update,
76 Delete,
78}
79
80impl fmt::Display for FhirOperation {
81 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82 match self {
83 FhirOperation::Read => write!(f, "read"),
84 FhirOperation::Search => write!(f, "search"),
85 FhirOperation::Create => write!(f, "create"),
86 FhirOperation::Update => write!(f, "update"),
87 FhirOperation::Delete => write!(f, "delete"),
88 }
89 }
90}