feat: store user agent with sessions

This commit is contained in:
Jef Roosens 2025-03-29 15:37:50 +01:00
parent 5112a6ce35
commit 2c44f788d9
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
9 changed files with 23 additions and 5 deletions

View file

@ -1,7 +1,5 @@
use std::time::Duration;
use tracing_subscriber::util::SubscriberInitExt;
use crate::server;
pub fn serve(config: &crate::config::Config) -> u8 {

View file

@ -5,10 +5,11 @@ use axum::{
};
use axum_extra::{
extract::{cookie::Cookie, CookieJar},
headers::{authorization::Basic, Authorization},
headers::{authorization::Basic, Authorization, UserAgent},
TypedHeader,
};
use cookie::time::Duration;
use gpodder::AuthErr;
use crate::server::{
error::{AppError, AppResult},
@ -27,6 +28,7 @@ async fn post_login(
Path(username): Path<String>,
jar: CookieJar,
TypedHeader(auth): TypedHeader<Authorization<Basic>>,
user_agent: Option<TypedHeader<UserAgent>>,
) -> AppResult<CookieJar> {
// These should be the same according to the spec
if username != auth.username() {
@ -62,7 +64,11 @@ async fn post_login(
let user = ctx
.store
.validate_credentials(auth.username(), auth.password())?;
ctx.store.create_session(&user)
let user_agent = user_agent.map(|header| header.to_string());
let session = ctx.store.create_session(&user, user_agent)?;
Ok::<_, AuthErr>(session)
})
.await
.unwrap()?;