rain_sdk/auth.rs
1//! Authentication module for API key management
2//!
3//! This module provides authentication functionality for the Rain SDK.
4//! It supports API key authentication via the `Api-Key` header.
5//!
6//! # Authentication Methods
7//!
8//! ## API Key Authentication
9//!
10//! Simple authentication using an API key:
11//!
12//! ```no_run
13//! use rain_sdk::AuthConfig;
14//!
15//! let auth = AuthConfig::with_api_key("your-api-key".to_string());
16//! ```
17
18/// Authentication configuration
19///
20/// Configures how the client authenticates with the Rain API.
21/// Supports API key authentication via the `Api-Key` header.
22///
23/// # Examples
24///
25/// ```no_run
26/// use rain_sdk::AuthConfig;
27///
28/// // API key authentication
29/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
30/// ```
31#[derive(Debug, Clone)]
32pub struct AuthConfig {
33 /// API key for Api-Key header
34 pub api_key: String,
35}
36
37impl AuthConfig {
38 /// Create new auth config with API key
39 ///
40 /// This method uses simple API key authentication via the `Api-Key` header.
41 ///
42 /// # Arguments
43 ///
44 /// * `api_key` - Your Rain API key
45 ///
46 /// # Examples
47 ///
48 /// ```no_run
49 /// use rain_sdk::AuthConfig;
50 ///
51 /// let auth = AuthConfig::with_api_key("your-api-key".to_string());
52 /// ```
53 pub fn with_api_key(api_key: String) -> Self {
54 Self { api_key }
55 }
56}
57
58/// Add authentication headers to a request builder
59#[cfg(feature = "async")]
60pub fn add_auth_headers_async(
61 builder: reqwest::RequestBuilder,
62 auth_config: &AuthConfig,
63) -> reqwest::RequestBuilder {
64 builder.header("Api-Key", &auth_config.api_key)
65}
66
67/// Add authentication headers to a request builder (blocking)
68#[cfg(feature = "sync")]
69pub fn add_auth_headers_sync(
70 builder: reqwest::blocking::RequestBuilder,
71 auth_config: &AuthConfig,
72) -> reqwest::blocking::RequestBuilder {
73 builder.header("Api-Key", &auth_config.api_key)
74}