1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-23 11:02:35 +03:00

Clean up some warp filters and add documentation

This commit is contained in:
Quentin Gliech
2021-09-23 14:02:44 +02:00
parent 9cd7dec070
commit 29126e336e
25 changed files with 196 additions and 109 deletions

View File

@@ -48,8 +48,8 @@ use crate::{
config::{CookiesConfig, OAuth2ClientConfig, OAuth2Config},
errors::WrapError,
filters::{
database::with_transaction,
session::{with_optional_session, with_session},
database::transaction,
session::{optional_session, session},
with_templates,
},
handlers::views::LoginRequest,
@@ -207,15 +207,15 @@ pub fn filter(
.and(warp::get())
.map(move || clients.clone())
.and(warp::query())
.and(with_optional_session(pool, cookies_config))
.and(with_transaction(pool))
.and(optional_session(pool, cookies_config))
.and(transaction(pool))
.and_then(get);
let step = warp::path!("oauth2" / "authorize" / "step")
.and(warp::get())
.and(warp::query().map(|s: StepRequest| s.id))
.and(with_session(pool, cookies_config))
.and(with_transaction(pool))
.and(session(pool, cookies_config))
.and(transaction(pool))
.and_then(step);
let clients = oauth2_config.clients.clone();

View File

@@ -23,7 +23,7 @@ use crate::{
errors::WrapError,
filters::{
client::{with_client_auth, ClientAuthentication},
database::with_connection,
database::connection,
},
storage::oauth2::{access_token::lookup_access_token, refresh_token::lookup_refresh_token},
tokens,
@@ -35,7 +35,7 @@ pub fn filter(
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone + Send + Sync + 'static {
warp::path!("oauth2" / "introspect")
.and(warp::post())
.and(with_connection(pool))
.and(connection(pool))
.and(with_client_auth(oauth2_config))
.and_then(introspect)
.recover(recover)

View File

@@ -41,10 +41,10 @@ use crate::{
errors::WrapError,
filters::{
client::{with_client_auth, ClientAuthentication},
database::with_connection,
headers::typed_header,
database::connection,
with_keys,
},
reply::with_typed_header,
storage::oauth2::{
access_token::{add_access_token, revoke_access_token},
authorization_code::{consume_code, lookup_code},
@@ -94,7 +94,7 @@ pub fn filter(
.and(with_client_auth(oauth2_config))
.and(with_keys(oauth2_config))
.and(warp::any().map(move || issuer.clone()))
.and(with_connection(pool))
.and(connection(pool))
.and_then(token)
.recover(recover)
}
@@ -130,10 +130,9 @@ async fn token(
}
};
Ok(typed_header(
Pragma::no_cache(),
typed_header(CacheControl::new().with_no_store(), reply),
))
let reply = with_typed_header(CacheControl::new().with_no_store(), reply);
let reply = with_typed_header(Pragma::no_cache(), reply);
Ok(reply)
}
fn hash<H: Digest>(mut hasher: H, token: &str) -> anyhow::Result<String> {

View File

@@ -18,7 +18,7 @@ use warp::{Filter, Rejection, Reply};
use crate::{
config::OAuth2Config,
filters::authenticate::{recover_unauthorized, with_authentication},
filters::authenticate::{recover_unauthorized, authentication},
storage::oauth2::access_token::OAuth2AccessTokenLookup,
};
@@ -33,7 +33,7 @@ pub(super) fn filter(
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone + Send + Sync + 'static {
warp::path!("oauth2" / "userinfo")
.and(warp::get().or(warp::post()).unify())
.and(with_authentication(pool))
.and(authentication(pool))
.and_then(userinfo)
.recover(recover_unauthorized)
}