ui(account): add security key management
This commit is contained in:
parent
31c2ef5279
commit
3c21770c25
7 changed files with 148 additions and 10 deletions
|
@ -1,23 +1,23 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export interface Key {
|
||||
export interface WebauthnKey {
|
||||
id: number;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
lastUsedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToKey = (data: any): Key => ({
|
||||
export const rawDataToWebauthnKey = (data: any): WebauthnKey => ({
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
createdAt: new Date(data.created_at),
|
||||
lastUsedAt: new Date(data.last_used_at) || new Date(),
|
||||
});
|
||||
|
||||
export default (): Promise<Key[]> => {
|
||||
export default (): Promise<WebauthnKey[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/client/account/webauthn')
|
||||
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToKey(d.attributes))))
|
||||
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToWebauthnKey(d.attributes))))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
import http from '@/api/http';
|
||||
import { Key, rawDataToKey } from '@/api/account/webauthn/getWebauthn';
|
||||
import { rawDataToWebauthnKey, WebauthnKey } from '@/api/account/webauthn/getWebauthnKeys';
|
||||
|
||||
export const base64Decode = (input: string): string => {
|
||||
input = input.replace(/-/g, '+').replace(/_/g, '/');
|
||||
|
@ -32,7 +32,7 @@ export const decodeCredentials = (credentials: PublicKeyCredentialDescriptor[])
|
|||
});
|
||||
};
|
||||
|
||||
export default (name: string): Promise<Key> => {
|
||||
export default (name: string): Promise<WebauthnKey> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/client/account/webauthn/register').then((res) => {
|
||||
const publicKey = res.data.public_key;
|
||||
|
@ -67,7 +67,7 @@ export default (name: string): Promise<Key> => {
|
|||
clientDataJSON: bufferEncode(response.clientDataJSON),
|
||||
},
|
||||
}),
|
||||
}).then(({ data }) => resolve(rawDataToKey(data.attributes))).catch(reject);
|
||||
}).then(({ data }) => resolve(rawDataToWebauthnKey(data.attributes))).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue