Add domain to the authentication cookie

This commit is contained in:
Jeremy Wall 2023-01-02 17:55:44 -06:00
parent ea2eb92a99
commit 09058914b0
2 changed files with 8 additions and 6 deletions

10
Cargo.lock generated
View File

@ -165,7 +165,7 @@ dependencies = [
"anyhow", "anyhow",
"async-lock", "async-lock",
"async-trait", "async-trait",
"base64 0.13.1", "base64 0.13.0",
"bincode", "bincode",
"blake3", "blake3",
"chrono", "chrono",
@ -292,7 +292,7 @@ checksum = "f9770f9a9147b2324066609acb5495538cb25f973129663fba2658ba7ed69407"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core", "axum-core",
"base64 0.13.1", "base64 0.13.0",
"http", "http",
] ]
@ -1064,7 +1064,7 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cff78e5788be1e0ab65b04d306b2ed5092c815ec97ec70f4ebd5aee158aa55d" checksum = "4cff78e5788be1e0ab65b04d306b2ed5092c815ec97ec70f4ebd5aee158aa55d"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.0",
"bitflags", "bitflags",
"bytes", "bytes",
"headers-core", "headers-core",
@ -1831,7 +1831,7 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.0",
] ]
[[package]] [[package]]
@ -2396,7 +2396,7 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.0",
"bitflags", "bitflags",
"bytes", "bytes",
"futures-core", "futures-core",

View File

@ -16,7 +16,7 @@ use std::sync::Arc;
use async_session::{Session, SessionStore}; use async_session::{Session, SessionStore};
use axum::{ use axum::{
extract::Extension, extract::{Extension, Host},
http::{header, HeaderMap, StatusCode}, http::{header, HeaderMap, StatusCode},
}; };
use axum_auth::AuthBasic; use axum_auth::AuthBasic;
@ -38,6 +38,7 @@ impl From<UserCreds> for api::AccountResponse {
#[instrument(skip_all, fields(user=%auth.0.0))] #[instrument(skip_all, fields(user=%auth.0.0))]
pub async fn handler( pub async fn handler(
auth: AuthBasic, auth: AuthBasic,
Host(domain): Host,
Extension(session_store): Extension<Arc<storage::SqliteStore>>, Extension(session_store): Extension<Arc<storage::SqliteStore>>,
) -> (StatusCode, HeaderMap, axum::Json<api::AccountResponse>) { ) -> (StatusCode, HeaderMap, axum::Json<api::AccountResponse>) {
// NOTE(jwall): It is very important that you do **not** log the password // NOTE(jwall): It is very important that you do **not** log the password
@ -93,6 +94,7 @@ pub async fn handler(
// 3. Construct the Session Cookie. // 3. Construct the Session Cookie.
let cookie = Cookie::build(storage::AXUM_SESSION_COOKIE_NAME, cookie_value) let cookie = Cookie::build(storage::AXUM_SESSION_COOKIE_NAME, cookie_value)
.same_site(SameSite::Strict) .same_site(SameSite::Strict)
.domain(domain)
.secure(true) .secure(true)
.path("/") .path("/")
.finish(); .finish();