Add support for security keys password

This commit is contained in:
2021-07-11 17:55:47 +02:00
parent 0cd6de200d
commit b7b1962886
4 changed files with 66 additions and 14 deletions

View File

@ -15,10 +15,12 @@ export interface AdminAccountKey {
id: number;
name: string;
time_add: number;
has_password: boolean;
}
export interface AuthKey {
name: string;
id: number;
password: boolean;
}
export class AdminKeyHelper {
@ -42,8 +44,13 @@ export class AdminKeyHelper {
*
* @param name The name of the key to create
* @param cred The credentials to register
* @param password The password required to use the key
*/
static async RegisterKey(name: string, cred: any): Promise<void> {
static async RegisterKey(
name: string,
cred: any,
password: string
): Promise<void> {
const res = {
id: cred.id,
rawId: ArrayBufferToBase64(cred.rawId),
@ -61,6 +68,7 @@ export class AdminKeyHelper {
await serverRequest("keys/register_key", {
name: name,
key: JSON.stringify(res),
password: password,
});
}
@ -96,11 +104,13 @@ export class AdminKeyHelper {
* @param mail Target admin account email address
* @param key Key used to authenticate
* @param cred Response to authentication
* @param password The password associated with the key (if any)
*/
static async AuthenticateWithKey(
mail: string,
key: AuthKey,
cred: any
cred: any,
password: string
): Promise<any> {
const creds = {
id: cred.id,
@ -122,6 +132,7 @@ export class AdminKeyHelper {
mail: mail,
key_id: key.id,
credential: JSON.stringify(creds),
password: password,
});
sessionStorage.setItem(SESSION_STORAGE_TOKEN, res.token);