diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-05 13:26:52 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-05 13:26:52 +0100 |
commit | 6b70b59d1c1e253d1837fa150460b61ab361aa13 (patch) | |
tree | 875e26916bb579bd8fb6e6d358549f0a6e6ef06a /server/src/routes/ui/account | |
parent | 51ba936859f14c2b39e2b181c16e4c024b93e71b (diff) | |
download | jellything-6b70b59d1c1e253d1837fa150460b61ab361aa13.tar jellything-6b70b59d1c1e253d1837fa150460b61ab361aa13.tar.bz2 jellything-6b70b59d1c1e253d1837fa150460b61ab361aa13.tar.zst |
fix jellyfin auth
Diffstat (limited to 'server/src/routes/ui/account')
-rw-r--r-- | server/src/routes/ui/account/session/guard.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/server/src/routes/ui/account/session/guard.rs b/server/src/routes/ui/account/session/guard.rs index 3a3f6d7..f85dace 100644 --- a/server/src/routes/ui/account/session/guard.rs +++ b/server/src/routes/ui/account/session/guard.rs @@ -23,8 +23,14 @@ impl Session { { let token = req .query_value("session") - .or(req.query_value("api_key")) - .or(req.headers().get_one("X-MediaBrowser-Token").map(Ok)) // for jellyfin compat + .or_else(|| req.query_value("api_key")) + .or_else(|| req.headers().get_one("X-MediaBrowser-Token").map(Ok)) + .or_else(|| { + req.headers() + .get_one("Authorization") + .and_then(parse_jellyfin_auth) + .map(Ok) + }) // for jellyfin compat .map(|e| e.expect("str parse should not fail, right?")) .or(req.cookies().get("session").map(|cookie| cookie.value())) .ok_or(anyhow!("not logged in"))?; @@ -45,6 +51,17 @@ impl Session { } } +fn parse_jellyfin_auth(h: &str) -> Option<&str> { + for tok in h.split(" ") { + if let Some(tok) = tok.strip_prefix("Token=\"") { + if let Some(tok) = tok.strip_suffix("\"") { + return Some(tok); + } + } + } + None +} + #[async_trait] impl<'r> FromRequest<'r> for Session { type Error = MyError; |