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

Dedicated HTTP server/client crate

Also have better names for the HTTP routes
This commit is contained in:
Quentin Gliech
2022-02-09 13:55:13 +01:00
parent 459ae34ebb
commit 2df40762a2
27 changed files with 335 additions and 126 deletions

View File

@@ -40,6 +40,7 @@ use mas_templates::{FormPostContext, Templates};
use mas_warp_utils::{
errors::WrapError,
filters::{
self,
database::transaction,
session::{optional_session, session},
with_templates,
@@ -222,6 +223,7 @@ pub fn filter(
let clients_config_2 = clients_config.clone();
let authorize = warp::path!("oauth2" / "authorize")
.and(filters::trace::name("GET /oauth2/authorize"))
.and(warp::get())
.map(move || clients_config.clone())
.and(warp::query())
@@ -230,6 +232,7 @@ pub fn filter(
.and_then(get);
let step = warp::path!("oauth2" / "authorize" / "step")
.and(filters::trace::name("GET /oauth2/authorize/step"))
.and(warp::get())
.and(warp::query())
.and(session(pool, encrypter))

View File

@@ -23,7 +23,7 @@ use mas_iana::{
},
};
use mas_jose::SigningKeystore;
use mas_warp_utils::filters::url_builder::UrlBuilder;
use mas_warp_utils::filters::{self, url_builder::UrlBuilder};
use oauth2_types::{
oidc::{ClaimType, Metadata, SubjectType},
requests::{Display, GrantType, ResponseMode},
@@ -184,6 +184,7 @@ pub(super) fn filter(
};
warp::path!(".well-known" / "openid-configuration")
.and(filters::trace::name("GET /.well-known/configuration"))
.and(warp::get())
.map(move || {
let ret: Box<dyn Reply> = Box::new(warp::reply::json(&metadata));

View File

@@ -20,7 +20,7 @@ use mas_storage::oauth2::{
};
use mas_warp_utils::{
errors::WrapError,
filters::{client::client_authentication, database::connection, url_builder::UrlBuilder},
filters::{self, client::client_authentication, database::connection, url_builder::UrlBuilder},
};
use oauth2_types::requests::{IntrospectionRequest, IntrospectionResponse};
use sqlx::{pool::PoolConnection, PgPool, Postgres};
@@ -37,6 +37,7 @@ pub fn filter(
.to_string();
warp::path!("oauth2" / "introspect")
.and(filters::trace::name("POST /oauth2/introspect"))
.and(
warp::post()
.and(connection(pool))

View File

@@ -15,12 +15,13 @@
use std::sync::Arc;
use mas_jose::{ExportJwks, StaticKeystore};
use mas_warp_utils::errors::WrapError;
use mas_warp_utils::{errors::WrapError, filters};
use warp::{filters::BoxedFilter, Filter, Rejection, Reply};
pub(super) fn filter(key_store: &Arc<StaticKeystore>) -> BoxedFilter<(Box<dyn Reply>,)> {
let key_store = key_store.clone();
warp::path!("oauth2" / "keys.json")
.and(filters::trace::name("GET /oauth2/keys.json"))
.and(warp::get().map(move || key_store.clone()).and_then(get))
.boxed()
}

View File

@@ -37,7 +37,7 @@ use mas_storage::{
};
use mas_warp_utils::{
errors::WrapError,
filters::{client::client_authentication, database::connection, url_builder::UrlBuilder},
filters::{self, client::client_authentication, database::connection, url_builder::UrlBuilder},
reply::with_typed_header,
};
use oauth2_types::{
@@ -108,6 +108,7 @@ pub fn filter(
let issuer = builder.oidc_issuer();
warp::path!("oauth2" / "token")
.and(filters::trace::name("POST /oauth2/token"))
.and(
warp::post()
.and(client_authentication(clients_config, audience))

View File

@@ -14,7 +14,10 @@
use mas_data_model::{AccessToken, Session};
use mas_storage::PostgresqlBackend;
use mas_warp_utils::filters::authenticate::{authentication, recover_unauthorized};
use mas_warp_utils::filters::{
self,
authenticate::{authentication, recover_unauthorized},
};
use serde::Serialize;
use sqlx::PgPool;
use warp::{filters::BoxedFilter, Filter, Rejection, Reply};
@@ -27,6 +30,7 @@ struct UserInfo {
pub(super) fn filter(pool: &PgPool) -> BoxedFilter<(Box<dyn Reply>,)> {
warp::path!("oauth2" / "userinfo")
.and(filters::trace::name("GET /oauth2/userinfo"))
.and(
warp::get()
.or(warp::post())