chrore: handlers/webauthn -> authentication
Build nomnom / Build-NomNom (push) Failing after 14m11s Details

This commit is contained in:
Félix Baylac Jacqué 2023-11-27 16:55:46 +01:00
parent 388646e7c7
commit e950366ebc
2 changed files with 19 additions and 9 deletions

View File

@ -1,4 +1,4 @@
use actix_web::{web, error, HttpResponse, http::header::ContentType, cookie::{Cookie, SameSite}};
use actix_web::{web, error, HttpResponse, http::header::{ContentType, self}, cookie::{Cookie, SameSite}, HttpRequest};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use webauthn_rs::prelude::{RegisterPublicKeyCredential, PasskeyRegistration, Passkey, RequestChallengeResponse, PublicKeyCredential};
@ -176,7 +176,7 @@ pub struct FinishLoginBody {
uuid: LoginUuid
}
pub async fn webauthn_login_finish(app_state: web::Data<AppState<'_>>, body: web::Json<FinishLoginBody>) -> impl actix_web::Responder {
pub async fn webauthn_login_finish(app_state: web::Data<AppState<'_>>, body: web::Json<FinishLoginBody>, req: HttpRequest) -> impl actix_web::Responder {
let passkey_auth = {
let mut user_logins = app_state.session.user_pending_logins.write().await;
let pk = user_logins.get(&body.uuid).cloned();
@ -209,7 +209,7 @@ pub async fn webauthn_login_finish(app_state: web::Data<AppState<'_>>, body: web
}
}
}
let response = templates::login(app_state.hbs.clone()).unwrap();
let redirect = req.cookie("redirect").map(|c| c.value().to_string());
#[cfg(debug_assertions)]
let secure = false;
#[cfg(not(debug_assertions))]
@ -217,10 +217,20 @@ pub async fn webauthn_login_finish(app_state: web::Data<AppState<'_>>, body: web
let auth_cookie = Cookie::build("auth-uuid", session_uuid.0.to_string())
.http_only(true)
.same_site(SameSite::Strict)
.path("/")
.secure(secure)
.finish();
HttpResponse::Ok()
.content_type(ContentType::html())
.cookie(auth_cookie)
.body(response)
match redirect {
Some(redirect) => {
HttpResponse::Found()
.append_header((header::LOCATION, redirect))
.cookie(auth_cookie)
.body("logged in")
}
None =>
HttpResponse::Ok()
.content_type(ContentType::html())
.cookie(auth_cookie)
.body("logged in")
}
}

View File

@ -2,9 +2,9 @@ use actix_web::{HttpResponse, http::header::ContentType, web};
use crate::{models::AppState, templates};
pub mod webauthn;
pub mod authentication;
pub use webauthn::*;
pub use authentication::*;
pub async fn landing_page (app_state: web::Data<AppState<'_>>) -> HttpResponse {
let content: String = templates::landing_page(app_state.hbs.clone()).unwrap();