mirror of https://github.com/mastodon/flodgatt
Read `access_token` from WS header (#44)
This commit is contained in:
parent
989c71059e
commit
0a8abde664
|
@ -302,7 +302,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flodgatt"
|
name = "flodgatt"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenv 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dotenv 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "flodgatt"
|
name = "flodgatt"
|
||||||
description = "A blazingly fast drop-in replacement for the Mastodon streaming api server"
|
description = "A blazingly fast drop-in replacement for the Mastodon streaming api server"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = ["Daniel Long Sockwell <daniel@codesections.com", "Julian Laubstein <contact@julianlaubstein.de>"]
|
authors = ["Daniel Long Sockwell <daniel@codesections.com", "Julian Laubstein <contact@julianlaubstein.de>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub fn optional_media_query() -> BoxedFilter<(Media,)> {
|
||||||
pub struct OptionalAccessToken;
|
pub struct OptionalAccessToken;
|
||||||
|
|
||||||
impl OptionalAccessToken {
|
impl OptionalAccessToken {
|
||||||
pub fn from_header() -> warp::filters::BoxedFilter<(Option<String>,)> {
|
pub fn from_sse_header() -> warp::filters::BoxedFilter<(Option<String>,)> {
|
||||||
let from_header = warp::header::header::<String>("authorization").map(|auth: String| {
|
let from_header = warp::header::header::<String>("authorization").map(|auth: String| {
|
||||||
match auth.split(' ').nth(1) {
|
match auth.split(' ').nth(1) {
|
||||||
Some(s) => Some(s.to_string()),
|
Some(s) => Some(s.to_string()),
|
||||||
|
@ -80,6 +80,13 @@ impl OptionalAccessToken {
|
||||||
});
|
});
|
||||||
let no_token = warp::any().map(|| None);
|
let no_token = warp::any().map(|| None);
|
||||||
|
|
||||||
|
from_header.or(no_token).unify().boxed()
|
||||||
|
}
|
||||||
|
pub fn from_ws_header() -> warp::filters::BoxedFilter<(Option<String>,)> {
|
||||||
|
let from_header =
|
||||||
|
warp::header::header::<String>("Sec-Websocket-Protocol").map(|auth: String| Some(auth));
|
||||||
|
let no_token = warp::any().map(|| None);
|
||||||
|
|
||||||
from_header.or(no_token).unify().boxed()
|
from_header.or(no_token).unify().boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub fn extract_user_or_reject() -> BoxedFilter<(User,)> {
|
||||||
)
|
)
|
||||||
// because SSE requests place their `access_token` in the header instead of in a query
|
// because SSE requests place their `access_token` in the header instead of in a query
|
||||||
// parameter, we need to update our Query if the header has a token
|
// parameter, we need to update our Query if the header has a token
|
||||||
.and(query::OptionalAccessToken::from_header())
|
.and(query::OptionalAccessToken::from_sse_header())
|
||||||
.and_then(Query::update_access_token)
|
.and_then(Query::update_access_token)
|
||||||
.and_then(User::from_query)
|
.and_then(User::from_query)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
|
|
@ -30,7 +30,11 @@ fn parse_query() -> BoxedFilter<(Query,)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extract_user_or_reject() -> BoxedFilter<(User,)> {
|
pub fn extract_user_or_reject() -> BoxedFilter<(User,)> {
|
||||||
parse_query().and_then(User::from_query).boxed()
|
parse_query()
|
||||||
|
.and(query::OptionalAccessToken::from_ws_header())
|
||||||
|
.and_then(Query::update_access_token)
|
||||||
|
.and_then(User::from_query)
|
||||||
|
.boxed()
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
Loading…
Reference in New Issue