Creates a new session with time-based access token Flow: 1. Derive master key from admin key and user key 2. Generate token key using current timestamp 3. Create and sign payload (username + timestamp) 4. Encode final token in URL-safe base64
(
username: &str,
admin_key: &SingleSHA256Hash,
user_key: &SingleSHA256Hash,
)
| 135 | // 3. Create and sign payload (username + timestamp) |
| 136 | // 4. Encode final token in URL-safe base64 |
| 137 | pub fn create_session( |
| 138 | username: &str, |
| 139 | admin_key: &SingleSHA256Hash, |
| 140 | user_key: &SingleSHA256Hash, |
| 141 | ) -> (String, u64) { |
| 142 | // Generate master key from user credentials |
| 143 | let master_key = MasterKey::new(admin_key, user_key); |
| 144 | |
| 145 | // Get current timestamp for token |
| 146 | let timestamp = get_current_timestamp(); |
| 147 | |
| 148 | // Generate time-based token key |
| 149 | let token_key = generate_token_key(&master_key, timestamp); |
| 150 | |
| 151 | // Create payload with username and timestamp |
| 152 | let payload = format!("{}|{}", username, timestamp); |
| 153 | |
| 154 | // Sign and encode final access token |
| 155 | let access_token = URL_SAFE_NO_PAD.encode(hmac::sign(&token_key, payload.as_bytes())); |
| 156 | |
| 157 | (access_token, timestamp) |
| 158 | } |
| 159 | |
| 160 | #[cfg(test)] |
| 161 | mod tests { |
nothing calls this directly
no test coverage detected