pub struct ApiKeyConfig {
pub enabled: bool,
pub keys: Vec<String>,
pub header_name: String,
pub query_param_name: String,
pub allow_query_param: bool,
pub key_prefix: String,
}Expand description
API Key configuration
Fields§
§enabled: boolWhether API key authentication is enabled
keys: Vec<String>List of valid API key hashes in PHC format.
For backward compatibility, plain-text keys are also accepted and will be
verified with a constant-time string comparison fallback.
New deployments should store only hashed keys generated by
ApiKeyConfig::generate_key().
header_name: StringHeader name for API key (default: “X-API-Key”)
query_param_name: StringQuery parameter name for API key (default: api_key)
allow_query_param: boolWhether to allow API key in query parameters (less secure)
key_prefix: StringAPI key prefix used by generated keys (e.g., “sk”)
Implementations§
Source§impl ApiKeyConfig
impl ApiKeyConfig
Sourcepub fn is_valid_key(&self, key: &str) -> bool
pub fn is_valid_key(&self, key: &str) -> bool
Check if a key is valid
Sourcepub fn generate_key(&self) -> Result<GeneratedApiKey>
pub fn generate_key(&self) -> Result<GeneratedApiKey>
Generate a new API key and corresponding hash using api-keys-simplified.
The returned plain-text key should be shown once and then discarded. Persist only the returned hash.
§Errors
Returns an error if key generation fails
Sourcepub fn normalize_key_material(&self, key: &str) -> Result<String>
pub fn normalize_key_material(&self, key: &str) -> Result<String>
Normalize API key material for storage.
- Structured Argon2 hashes are kept as-is
- Legacy plain-text keys are converted to
legacy:-prefixed Argon2 hashes - Plain-text fallback remains supported for backward compatibility
§Errors
Returns an error if hashing legacy key material fails.
Trait Implementations§
Source§impl Clone for ApiKeyConfig
impl Clone for ApiKeyConfig
Source§fn clone(&self) -> ApiKeyConfig
fn clone(&self) -> ApiKeyConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ApiKeyConfig
impl Debug for ApiKeyConfig
Source§impl Default for ApiKeyConfig
Available on crate feature api-key only.
impl Default for ApiKeyConfig
api-key only.