wip passkey registration day 2
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
use dioxus::prelude::*;
|
||||
use web_sys::{CredentialCreationOptions, window};
|
||||
use js_sys::{Uint8Array, wasm_bindgen::JsValue};
|
||||
use web_sys::{
|
||||
CredentialCreationOptions, PublicKeyCredentialCreationOptions, PublicKeyCredentialRpEntity,
|
||||
PublicKeyCredentialUserEntity, window,
|
||||
};
|
||||
|
||||
use crate::components::basic::Button;
|
||||
use crate::{components::basic::Button, rpc::aoba::PasskeyCredentialCreateOptions};
|
||||
|
||||
#[component]
|
||||
pub fn PasskeyRegistrationButton() -> Element {
|
||||
pub fn PasskeyRegistrationButton() -> Element
|
||||
{
|
||||
rsx! {
|
||||
Button{
|
||||
text: "Register Passkey",
|
||||
@@ -15,22 +20,55 @@ pub fn PasskeyRegistrationButton() -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
fn start_passkey_registration() {
|
||||
create_credential();
|
||||
fn start_passkey_registration()
|
||||
{
|
||||
create_credential(todo!());
|
||||
}
|
||||
|
||||
fn create_credential() {
|
||||
let credentials = window()
|
||||
.expect("Failed to get window")
|
||||
.navigator()
|
||||
.credentials();
|
||||
fn create_credential(req_opts: PasskeyCredentialCreateOptions)
|
||||
{
|
||||
let window = window().expect("Window does not exist");
|
||||
let credentaials = window.navigator().credentials();
|
||||
|
||||
let opts = opts_from_rpc(req_opts);
|
||||
|
||||
let result = credentaials.create_with_options(&opts);
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn opts_from_rpc(rpc_opts: PasskeyCredentialCreateOptions) -> CredentialCreationOptions
|
||||
{
|
||||
let opt_user = &rpc_opts.user.expect("user is missing");
|
||||
let opt_rp = &rpc_opts.rp.expect("rp is missing");
|
||||
let opts = CredentialCreationOptions::new();
|
||||
let _result = credentials.create_with_options(&opts);
|
||||
let rp = PublicKeyCredentialRpEntity::new(&opt_rp.name);
|
||||
rp.set_id(&opt_rp.id);
|
||||
|
||||
let user = PublicKeyCredentialUserEntity::new_with_u8_array(
|
||||
&opt_user.name,
|
||||
&opt_user.display_name,
|
||||
&to_u8_array(&opt_user.id),
|
||||
);
|
||||
let pub_key_opts = PublicKeyCredentialCreationOptions::new_with_u8_array(
|
||||
&to_u8_array(&rpc_opts.challenge),
|
||||
&JsValue::undefined(),
|
||||
&rp,
|
||||
&user,
|
||||
);
|
||||
//pub_key_opts.set_exclude_credentials(val);
|
||||
opts.set_public_key(&pub_key_opts);
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
fn to_u8_array(value: &String) -> Uint8Array
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn PasskeyLoginButton() -> Element {
|
||||
pub fn PasskeyLoginButton() -> Element
|
||||
{
|
||||
rsx! {
|
||||
Button{
|
||||
text: "Login with Passkey"
|
||||
|
||||
+18
-1
@@ -6,7 +6,9 @@ use tonic_web_wasm_client::Client;
|
||||
|
||||
use crate::{
|
||||
RPC_HOST,
|
||||
rpc::aoba::{auth_rpc_client::AuthRpcClient, metrics_rpc_client::MetricsRpcClient},
|
||||
rpc::aoba::{
|
||||
account_rpc_client::AccountRpcClient, auth_rpc_client::AuthRpcClient, metrics_rpc_client::MetricsRpcClient,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod aoba
|
||||
@@ -17,6 +19,7 @@ pub mod aoba
|
||||
static RPC_CLIENT: RpcConnection = RpcConnection {
|
||||
aoba: RwLock::new(None),
|
||||
auth: RwLock::new(None),
|
||||
account: RwLock::new(None),
|
||||
metrics: RwLock::new(None),
|
||||
jwt: RwLock::new(None),
|
||||
};
|
||||
@@ -26,6 +29,7 @@ pub struct RpcConnection
|
||||
{
|
||||
aoba: RwLock<Option<AobaRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
|
||||
auth: RwLock<Option<AuthRpcClient<Client>>>,
|
||||
account: RwLock<Option<AccountRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
|
||||
metrics: RwLock<Option<MetricsRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
|
||||
jwt: RwLock<Option<String>>,
|
||||
}
|
||||
@@ -38,6 +42,12 @@ impl RpcConnection
|
||||
return self.aoba.read().unwrap().clone().unwrap();
|
||||
}
|
||||
|
||||
pub fn get_account_client(&self) -> AccountRpcClient<InterceptedService<Client, AuthInterceptor>>
|
||||
{
|
||||
self.ensure_client();
|
||||
return self.account.read().unwrap().clone().unwrap();
|
||||
}
|
||||
|
||||
pub fn get_auth_client(&self) -> AuthRpcClient<Client>
|
||||
{
|
||||
self.ensure_client();
|
||||
@@ -58,6 +68,8 @@ impl RpcConnection
|
||||
let aoba_client = AobaRpcClient::with_interceptor(wasm_client.clone(), AuthInterceptor);
|
||||
*self.aoba.write().unwrap() = Some(aoba_client);
|
||||
*self.auth.write().unwrap() = Some(AuthRpcClient::new(wasm_client.clone()));
|
||||
*self.account.write().unwrap() =
|
||||
Some(AccountRpcClient::with_interceptor(wasm_client.clone(), AuthInterceptor));
|
||||
*self.metrics.write().unwrap() =
|
||||
Some(MetricsRpcClient::with_interceptor(wasm_client.clone(), AuthInterceptor));
|
||||
}
|
||||
@@ -90,6 +102,11 @@ pub fn get_auth_rpc_client() -> AuthRpcClient<Client>
|
||||
return RPC_CLIENT.get_auth_client();
|
||||
}
|
||||
|
||||
pub fn get_account_rpc_client() -> AccountRpcClient<InterceptedService<Client, AuthInterceptor>>
|
||||
{
|
||||
return RPC_CLIENT.get_account_client();
|
||||
}
|
||||
|
||||
pub fn get_metrics_rpc_client() -> MetricsRpcClient<InterceptedService<Client, AuthInterceptor>>
|
||||
{
|
||||
return RPC_CLIENT.get_metrics_client();
|
||||
|
||||
Reference in New Issue
Block a user