Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace ad hoc auth header with internet standard bearer token auth header #3982

Merged
merged 8 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ actix-web = { version = "4.3.1", default-features = false, features = [
"compress-gzip",
"compress-zstd",
] }
actix-web-httpauth = "0.8.1"
tracing = "0.1.37"
tracing-actix-web = { version = "0.7.5", default-features = false }
tracing-error = "0.2.0"
Expand Down Expand Up @@ -168,4 +169,5 @@ prometheus = { version = "0.13.3", features = ["process"], optional = true }
actix-web-prom = { version = "0.6.0", optional = true }
serial_test = { workspace = true }
clap = { version = "4.3.19", features = ["derive"] }
actix-web-httpauth = { workspace = true }
lemmy_federate = { version = "0.18.4", path = "crates/federate" }
1 change: 1 addition & 0 deletions crates/api_crud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ activitypub_federation = { workspace = true }
bcrypt = { workspace = true }
serde = { workspace = true }
actix-web = { workspace = true }
actix-web-httpauth = { workspace = true }
SleeplessOne1917 marked this conversation as resolved.
Show resolved Hide resolved
tracing = { workspace = true }
url = { workspace = true }
async-trait = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/translations
8 changes: 4 additions & 4 deletions docker/federation/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ version: "3.7"

x-ui-default: &ui-default
init: true
image: dessalines/lemmy-ui:0.18.4
# image: dessalines/lemmy-ui:0.18.4
# assuming lemmy-ui is cloned besides lemmy directory
# build:
# context: ../../../lemmy-ui
# dockerfile: dev.dockerfile
build:
context: ../../../lemmy-ui
dockerfile: dev.dockerfile
SleeplessOne1917 marked this conversation as resolved.
Show resolved Hide resolved
environment:
- LEMMY_UI_HTTPS=false

Expand Down
11 changes: 4 additions & 7 deletions src/session_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use actix_web::{
body::MessageBody,
cookie::SameSite,
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
http::header::CACHE_CONTROL,
http::header::{Header, CACHE_CONTROL},
Error,
HttpMessage,
};
use actix_web_httpauth::headers::authorization::{Authorization, Bearer};
use chrono::{DateTime, Utc};
use core::future::Ready;
use futures_util::future::LocalBoxFuture;
Expand Down Expand Up @@ -76,13 +77,9 @@ where
let context = self.context.clone();

Box::pin(async move {
// Try reading jwt from auth header
let auth_header = req
.headers()
.get(AUTH_COOKIE_NAME)
.and_then(|h| h.to_str().ok());
let auth_header = Authorization::<Bearer>::parse(&req).ok();
let jwt = if let Some(a) = auth_header {
Some(a.to_string())
Some(a.as_ref().token().to_string())
}
// If that fails, try auth cookie. Dont use the `jwt` cookie from lemmy-ui because
// its not http-only.
Expand Down