feat: store user agent with sessions
This commit is contained in:
parent
5112a6ce35
commit
2c44f788d9
9 changed files with 23 additions and 5 deletions
|
|
@ -1,7 +1,5 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
use crate::server;
|
||||
|
||||
pub fn serve(config: &crate::config::Config) -> u8 {
|
||||
|
|
|
|||
|
|
@ -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()?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue