Managed to authenticate user using Webauthn

This commit is contained in:
2022-04-23 20:17:49 +02:00
parent 05d3bee328
commit 9e345895ff
4 changed files with 54 additions and 4 deletions

View 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!")
}
}
}

View File

@ -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;