1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-07-06 15:52:48 +00:00

Can authenticate using security key

This commit is contained in:
2021-05-14 12:18:21 +02:00
parent c52b7a4408
commit 3c4a5a53a1
3 changed files with 39 additions and 0 deletions

View File

@ -154,4 +154,24 @@ pub fn challenge_auth_with_key(r: &mut HttpRequestHandler) -> RequestResult {
admin_key_authentication_challenges_helper::set(key.id, auth_state)?;
r.set_response(challenge_response)
}
/// Authenticate a user with a security key
pub fn auth_with_key(r: &mut HttpRequestHandler) -> RequestResult {
let key = r.post_admin_auth_key("mail", "key_id")?;
let credentials = r.post_auth_public_key_credential("credential")?;
let state = r.some_or_internal_error(
admin_key_authentication_challenges_helper::get(key.id)?,
"Associated authentication state not found!",
)?;
// Perform authentication
let state = get_wan().authenticate_credential(credentials, state)?;
r.some_or_bad_request(state, "Invalid key!")?;
// Generate access token
let token = admin_access_token_helper::create(key.admin_id)?;
r.set_response(AdminAuthSuccess::new(token))
}