mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Implement federated login; #123
This commit is contained in:
32
rc_auth/src/robocraft/displayname.rs
Normal file
32
rc_auth/src/robocraft/displayname.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use oj_rc_core::persist::user::FederatedAuthenticator;
|
||||
use actix_web::{post, web::{Data, Json}};
|
||||
|
||||
#[post("/authenticate/displayname/game")]
|
||||
pub async fn displaye_password_auth(body: Json<libfj::robocraft::EmailUserAuthenticationPayload>, config: Data<super::RcConfig>) -> Result<Json<libfj::robocraft::AuthenticationResponseInfo>, super::ErrorTy> {
|
||||
if body.display_name.is_none() {
|
||||
return Err(super::ErrorTy::from_err(oj_rc_core::persist::user::AuthError {
|
||||
message: "Missing display_name".to_owned(),
|
||||
code: oj_rc_core::data::error_codes::AuthErrorCode::BadCredentials,
|
||||
}));
|
||||
}
|
||||
let display_name = body.display_name.clone().unwrap();
|
||||
if let Some((display_name, domain)) = display_name.split_once('#') {
|
||||
log::info!("Authenticating {} user {} for domain {}", body.target, display_name, domain);
|
||||
let user_info = oj_rc_core::persist::user::FederatedAuthInfo {
|
||||
display_name: display_name.to_owned(),
|
||||
password: body.password.clone(),
|
||||
domain: domain.to_owned(),
|
||||
};
|
||||
let response = config.account_provider.local_login(user_info).await
|
||||
.map_err(|e| {
|
||||
log::error!("Failed to authenticate {} user {}#{}: {}", body.target, display_name, domain, e.message);
|
||||
super::ErrorTy::from_err(e)
|
||||
})?;
|
||||
Ok(Json(response.response))
|
||||
} else {
|
||||
Err(super::ErrorTy::from_err(oj_rc_core::persist::user::AuthError {
|
||||
message: "Missing display_name domain".to_owned(),
|
||||
code: oj_rc_core::data::error_codes::AuthErrorCode::InvalidDisplayName,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ use actix_web::{rt, web::{Payload, Data, Path, Json}, Error, HttpRequest, HttpRe
|
||||
|
||||
#[get("/intercom/.oj_services/{name}")]
|
||||
pub async fn services_ws(req: HttpRequest, stream: Payload, auth: Data<super::IntercomAuth>, reg: Data<super::Users>, name: Path<String>) -> Result<HttpResponse, Error> {
|
||||
auth.validate(&req, &format!(".oj_services/{}", name))?;
|
||||
log::debug!("intercom/.oj_services name is {}", name);
|
||||
auth.validate(&req, &format!(".oj_services/{}", urlencoding::encode(&*name)))?;
|
||||
let (res, mut session, _stream) = actix_ws::handle(&req, stream)?;
|
||||
|
||||
/*let mut stream = stream
|
||||
|
||||
@@ -3,6 +3,7 @@ pub mod registration;
|
||||
pub mod steam;
|
||||
pub mod username;
|
||||
pub mod intercom;
|
||||
pub mod displayname;
|
||||
|
||||
pub struct RcConfig {
|
||||
//pub data: std::path::PathBuf,
|
||||
|
||||
Reference in New Issue
Block a user