You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
WIP: Handle /login
This commit is contained in:
83
crates/handlers/src/compat/mod.rs
Normal file
83
crates/handlers/src/compat/mod.rs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
// 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::{response::IntoResponse, Json};
|
||||||
|
use hyper::StatusCode;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct MatrixError {
|
||||||
|
errcode: &'static str,
|
||||||
|
error: &'static str,
|
||||||
|
#[serde(skip)]
|
||||||
|
status: StatusCode,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoResponse for MatrixError {
|
||||||
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
(self.status, Json(self)).into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
enum LoginType {
|
||||||
|
#[serde(rename = "m.login.password")]
|
||||||
|
Password,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct LoginTypes {
|
||||||
|
flows: Vec<LoginType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get() -> impl IntoResponse {
|
||||||
|
let res = LoginTypes {
|
||||||
|
flows: vec![LoginType::Password],
|
||||||
|
};
|
||||||
|
|
||||||
|
Json(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum IncomingLogin {
|
||||||
|
#[serde(rename = "m.login.password")]
|
||||||
|
Password {
|
||||||
|
identifier: LoginIdentifier,
|
||||||
|
password: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[serde(other)]
|
||||||
|
Unsupported,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum LoginIdentifier {
|
||||||
|
#[serde(rename = "m.id.user")]
|
||||||
|
User { user: String },
|
||||||
|
|
||||||
|
#[serde(other)]
|
||||||
|
Unsupported,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn post(Json(input): Json<IncomingLogin>) -> impl IntoResponse {
|
||||||
|
tracing::info!(?input, "Got Matrix login");
|
||||||
|
MatrixError {
|
||||||
|
errcode: "M_UNKNOWN",
|
||||||
|
error: "Not implemented",
|
||||||
|
status: StatusCode::NOT_IMPLEMENTED,
|
||||||
|
}
|
||||||
|
}
|
@@ -39,6 +39,7 @@ use sqlx::PgPool;
|
|||||||
use tower::util::ThenLayer;
|
use tower::util::ThenLayer;
|
||||||
use tower_http::cors::{Any, CorsLayer};
|
use tower_http::cors::{Any, CorsLayer};
|
||||||
|
|
||||||
|
mod compat;
|
||||||
mod health;
|
mod health;
|
||||||
mod oauth2;
|
mod oauth2;
|
||||||
mod views;
|
mod views;
|
||||||
@@ -95,6 +96,10 @@ where
|
|||||||
mas_router::OAuth2RegistrationEndpoint::route(),
|
mas_router::OAuth2RegistrationEndpoint::route(),
|
||||||
post(self::oauth2::registration::post),
|
post(self::oauth2::registration::post),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
mas_router::CompatLogin::route(),
|
||||||
|
get(self::compat::get).post(self::compat::post),
|
||||||
|
)
|
||||||
.layer(
|
.layer(
|
||||||
CorsLayer::new()
|
CorsLayer::new()
|
||||||
.allow_origin(Any)
|
.allow_origin(Any)
|
||||||
|
@@ -366,3 +366,10 @@ impl Route for Consent {
|
|||||||
format!("/consent/{}", self.0).into()
|
format!("/consent/{}", self.0).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `GET|POST /_matrix/client/v3/login`
|
||||||
|
pub struct CompatLogin;
|
||||||
|
|
||||||
|
impl SimpleRoute for CompatLogin {
|
||||||
|
const PATH: &'static str = "/_matrix/client/:version/login";
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user