mirror of
https://gitlab.com/comunic/comunicconsole
synced 2025-06-20 00:25:19 +00:00
Can enroll keys
This commit is contained in:
@ -4,6 +4,10 @@
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
import {
|
||||
ArrayBufferToBase64,
|
||||
base64NoPaddingToUint8Array,
|
||||
} from "../utils/Base64Utils";
|
||||
import { serverRequest } from "./APIHelper";
|
||||
|
||||
export interface AuthOptions {
|
||||
@ -133,4 +137,49 @@ export class AccountHelper {
|
||||
email: s.email,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* First step of access key enrollment
|
||||
*/
|
||||
static async GetKeyRegistrationChallenge(): Promise<any> {
|
||||
const res = await serverRequest("accounts/challenge_register_key");
|
||||
res.publicKey.challenge = base64NoPaddingToUint8Array(
|
||||
res.publicKey.challenge
|
||||
);
|
||||
res.publicKey.user.id = base64NoPaddingToUint8Array(
|
||||
res.publicKey.user.id
|
||||
);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register key
|
||||
*
|
||||
* @param name The name of the key to create
|
||||
* @param cred The credentials to register
|
||||
*/
|
||||
static async RegisterKey(name: string, cred: any): Promise<void> {
|
||||
const res = {
|
||||
id: cred.id,
|
||||
rawId: ArrayBufferToBase64(cred.rawId),
|
||||
type: cred.type,
|
||||
response: {
|
||||
attestationObject: ArrayBufferToBase64(
|
||||
cred.response.attestationObject
|
||||
),
|
||||
clientDataJSON: ArrayBufferToBase64(
|
||||
cred.response.clientDataJSON
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
console.info(cred);
|
||||
console.info(res);
|
||||
|
||||
await serverRequest("accounts/register_key", {
|
||||
name: name,
|
||||
key: JSON.stringify(res),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user