Get auth challenge
This commit is contained in:
@ -2,8 +2,8 @@ use std::io::ErrorKind;
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web;
|
||||
use webauthn_rs::{RegistrationState, Webauthn, WebauthnConfig};
|
||||
use webauthn_rs::proto::{CreationChallengeResponse, Credential, RegisterPublicKeyCredential};
|
||||
use webauthn_rs::{AuthenticationState, RegistrationState, Webauthn, WebauthnConfig};
|
||||
use webauthn_rs::proto::{CreationChallengeResponse, Credential, RegisterPublicKeyCredential, RequestChallengeResponse};
|
||||
|
||||
use crate::constants::APP_NAME;
|
||||
use crate::data::app_config::AppConfig;
|
||||
@ -31,22 +31,34 @@ impl WebauthnConfig for WebAuthnAppConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RegisterKeyRequest {
|
||||
pub opaque_state: String,
|
||||
pub creation_challenge: CreationChallengeResponse,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct WebauthnPubKey {
|
||||
creds: Credential,
|
||||
}
|
||||
|
||||
pub struct RegisterKeyRequest {
|
||||
pub opaque_state: String,
|
||||
pub creation_challenge: CreationChallengeResponse,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
struct RegisterKeyOpaqueData {
|
||||
registration_state: RegistrationState,
|
||||
user_id: UserID,
|
||||
}
|
||||
|
||||
pub struct AuthRequest {
|
||||
pub opaque_state: String,
|
||||
pub login_challenge: RequestChallengeResponse,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
struct AuthStateOpaqueData {
|
||||
authentication_state: AuthenticationState,
|
||||
user_id: UserID,
|
||||
}
|
||||
|
||||
|
||||
pub type WebAuthManagerReq = web::Data<Arc<WebAuthManager>>;
|
||||
|
||||
pub struct WebAuthManager {
|
||||
@ -97,4 +109,18 @@ impl WebAuthManager {
|
||||
|
||||
Ok(WebauthnPubKey { creds: res.0 })
|
||||
}
|
||||
|
||||
pub fn start_authentication(&self, user_id: &UserID, key: &WebauthnPubKey) -> Res<AuthRequest> {
|
||||
let (login_challenge, authentication_state) = self.core.generate_challenge_authenticate(vec![
|
||||
key.creds.clone()
|
||||
])?;
|
||||
|
||||
Ok(AuthRequest {
|
||||
opaque_state: self.crypto_wrapper.encrypt(&AuthStateOpaqueData {
|
||||
authentication_state,
|
||||
user_id: user_id.clone(),
|
||||
})?,
|
||||
login_challenge,
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user