1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Basic Webfinger support

This commit is contained in:
Quentin Gliech
2022-04-08 10:43:38 +02:00
parent 819cdfd9d8
commit d43a8f1a00
5 changed files with 140 additions and 1 deletions

View File

@ -61,6 +61,7 @@ where
"/.well-known/openid-configuration",
get(self::oauth2::discovery::get),
)
.route("/.well-known/webfinger", get(self::oauth2::webfinger::get))
.route("/oauth2/keys.json", get(self::oauth2::keys::get))
.route(
"/oauth2/userinfo",

View File

@ -18,5 +18,6 @@ pub mod introspection;
pub mod keys;
pub mod token;
pub mod userinfo;
pub mod webfinger;
pub(crate) use authorization::ContinueAuthorizationGrant;

View File

@ -0,0 +1,53 @@
// Copyright 2022 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use axum::{extract::Query, response::IntoResponse, Extension, Json, TypedHeader};
use headers::ContentType;
use mas_axum_utils::UrlBuilder;
use oauth2_types::webfinger::WebFingerResponse;
use serde::Deserialize;
#[derive(Deserialize)]
pub(crate) struct Params {
resource: String,
// TODO: handle multiple rel=
#[serde(default)]
rel: Option<String>,
}
fn jrd() -> mime::Mime {
"application/jrd+json".parse().unwrap()
}
pub(crate) async fn get(
Query(params): Query<Params>,
Extension(url_builder): Extension<UrlBuilder>,
) -> impl IntoResponse {
// TODO: should we validate the subject?
let subject = params.resource;
let wants_issuer = params
.rel
.iter()
.any(|i| i == "http://openid.net/specs/connect/1.0/issuer");
let res = if wants_issuer {
WebFingerResponse::new(subject).with_issuer(url_builder.oidc_issuer())
} else {
WebFingerResponse::new(subject)
};
(TypedHeader(ContentType::from(jrd())), Json(res))
}