Managed to authenticate user using Webauthn
This commit is contained in:
33
src/controllers/login_api.rs
Normal file
33
src/controllers/login_api.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use actix_identity::Identity;
|
||||
use actix_web::{HttpResponse, Responder, web};
|
||||
use webauthn_rs::proto::PublicKeyCredential;
|
||||
|
||||
use crate::data::session_identity::{SessionIdentity, SessionStatus};
|
||||
use crate::data::webauthn_manager::WebAuthManagerReq;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct AuthWebauthnRequest {
|
||||
opaque_state: String,
|
||||
credential: PublicKeyCredential,
|
||||
}
|
||||
|
||||
pub async fn auth_webauthn(id: Identity,
|
||||
req: web::Json<AuthWebauthnRequest>,
|
||||
manager: WebAuthManagerReq) -> impl Responder {
|
||||
if !SessionIdentity(&id).need_2fa_auth() {
|
||||
return HttpResponse::Unauthorized().json("No 2FA required!");
|
||||
}
|
||||
|
||||
let user_id = SessionIdentity(&id).user_id();
|
||||
|
||||
match manager.finish_authentication(&user_id, &req.opaque_state, &req.credential) {
|
||||
Ok(_) => {
|
||||
SessionIdentity(&id).set_status(SessionStatus::SignedIn);
|
||||
HttpResponse::Ok().body("You are authenticated!")
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to authenticate user using webauthn! {:?}", e);
|
||||
HttpResponse::InternalServerError().body("Failed to validate security key!")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
pub mod assets_controller;
|
||||
pub mod base_controller;
|
||||
pub mod login_controller;
|
||||
pub mod login_api;
|
||||
pub mod settings_controller;
|
||||
pub mod admin_controller;
|
||||
pub mod admin_api;
|
||||
|
Reference in New Issue
Block a user