Can finalize Matrix authentication
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::controllers::{HttpFailure, HttpResult};
|
||||
use crate::extractors::auth_extractor::{AuthExtractor, AuthenticatedMethod};
|
||||
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
||||
use crate::extractors::session_extractor::MatrixGWSession;
|
||||
use crate::users::{ExtendedUserInfo, User, UserEmail};
|
||||
use crate::users::{User, UserEmail};
|
||||
use actix_remote_ip::RemoteIP;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use light_openid::primitives::OpenIDConfig;
|
||||
@@ -107,8 +108,8 @@ pub async fn finish_oidc(
|
||||
}
|
||||
|
||||
/// Get current user information
|
||||
pub async fn auth_info(auth: AuthExtractor) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(ExtendedUserInfo::from_user(auth.user).await?))
|
||||
pub async fn auth_info(client: MatrixClientExtractor) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(client.to_extended_user_info().await?))
|
||||
}
|
||||
|
||||
/// Sign out user
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
||||
use crate::matrix_connection::matrix_client::FinishMatrixAuth;
|
||||
use actix_web::HttpResponse;
|
||||
use anyhow::Context;
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct StartAuthResponse {
|
||||
@@ -12,3 +14,13 @@ pub async fn start_auth(client: MatrixClientExtractor) -> HttpResult {
|
||||
let url = client.client.initiate_login().await?.to_string();
|
||||
Ok(HttpResponse::Ok().json(StartAuthResponse { url }))
|
||||
}
|
||||
|
||||
/// Finish user authentication on Matrix server
|
||||
pub async fn finish_auth(client: MatrixClientExtractor) -> HttpResult {
|
||||
client
|
||||
.client
|
||||
.finish_login(client.auth.decode_json_body::<FinishMatrixAuth>()?)
|
||||
.await
|
||||
.context("Failed to finalize Matrix authentication!")?;
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ impl ResponseError for HttpFailure {
|
||||
}
|
||||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::build(self.status_code()).body(self.to_string())
|
||||
HttpResponse::build(self.status_code())
|
||||
.content_type("text/plain")
|
||||
.body(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user