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

Add a way to discover the GraphQL endpoint in the .well-known/openid-configuration

This adds a `org.matrix.matrix-authentication-service.graphql_endpoint` key to it
This commit is contained in:
Quentin Gliech
2023-09-18 19:19:39 +02:00
parent a62aa87b0c
commit 3303e74123
4 changed files with 40 additions and 4 deletions

View File

@@ -124,7 +124,7 @@ where
{ {
let mut router = Router::new() let mut router = Router::new()
.route( .route(
"/graphql", mas_router::GraphQL::route(),
get(self::graphql::get).post(self::graphql::post), get(self::graphql::get).post(self::graphql::post),
) )
.layer( .layer(
@@ -141,7 +141,10 @@ where
); );
if playground { if playground {
router = router.route("/graphql/playground", get(self::graphql::playground)); router = router.route(
mas_router::GraphQLPlayground::route(),
get(self::graphql::playground),
);
} }
router router

View File

@@ -25,6 +25,16 @@ use oauth2_types::{
requests::{Display, GrantType, Prompt, ResponseMode}, requests::{Display, GrantType, Prompt, ResponseMode},
scope, scope,
}; };
use serde::Serialize;
#[derive(Debug, Serialize)]
struct DiscoveryResponse {
#[serde(flatten)]
standard: ProviderMetadata,
#[serde(rename = "org.matrix.matrix-authentication-service.graphql_endpoint")]
graphql_endpoint: url::Url,
}
#[tracing::instrument(name = "handlers.oauth2.discovery.get", skip_all)] #[tracing::instrument(name = "handlers.oauth2.discovery.get", skip_all)]
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
@@ -122,7 +132,7 @@ pub(crate) async fn get(
let prompt_values_supported = Some(vec![Prompt::None, Prompt::Login, Prompt::Create]); let prompt_values_supported = Some(vec![Prompt::None, Prompt::Login, Prompt::Create]);
let metadata = ProviderMetadata { let standard = ProviderMetadata {
issuer, issuer,
authorization_endpoint, authorization_endpoint,
token_endpoint, token_endpoint,
@@ -155,7 +165,10 @@ pub(crate) async fn get(
..ProviderMetadata::default() ..ProviderMetadata::default()
}; };
Json(metadata) Json(DiscoveryResponse {
standard,
graphql_endpoint: url_builder.graphql_endpoint(),
})
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -692,3 +692,17 @@ impl Route for StaticAsset {
format!("/assets/{}", self.path).into() format!("/assets/{}", self.path).into()
} }
} }
/// `GET|POST /graphql`
pub struct GraphQL;
impl SimpleRoute for GraphQL {
const PATH: &'static str = "/graphql";
}
/// `GET /graphql/playground`
pub struct GraphQLPlayground;
impl SimpleRoute for GraphQLPlayground {
const PATH: &'static str = "/graphql/playground";
}

View File

@@ -121,6 +121,12 @@ impl UrlBuilder {
&self.assets_base &self.assets_base
} }
/// GraphQL endpoint
#[must_use]
pub fn graphql_endpoint(&self) -> Url {
self.url_for(&crate::endpoints::GraphQL)
}
/// Upstream redirect URI /// Upstream redirect URI
#[must_use] #[must_use]
pub fn upstream_oauth_callback(&self, id: Ulid) -> Url { pub fn upstream_oauth_callback(&self, id: Ulid) -> Url {