mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
code refactor
This commit is contained in:
@@ -159,6 +159,14 @@ export function base64encode(arrayBuffer) {
|
|||||||
return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)));
|
return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function base64decode(str) {
|
||||||
|
if (!str) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return atob(str);
|
||||||
|
}
|
||||||
|
|
||||||
export function arrayBufferToString(arrayBuffer) {
|
export function arrayBufferToString(arrayBuffer) {
|
||||||
return String.fromCharCode.apply(null, new Uint8Array(arrayBuffer));
|
return String.fromCharCode.apply(null, new Uint8Array(arrayBuffer));
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -4,7 +4,8 @@ import {
|
|||||||
isFunction,
|
isFunction,
|
||||||
stringToArrayBuffer,
|
stringToArrayBuffer,
|
||||||
arrayBufferToString,
|
arrayBufferToString,
|
||||||
base64encode
|
base64encode,
|
||||||
|
base64decode
|
||||||
} from './common.js';
|
} from './common.js';
|
||||||
import {
|
import {
|
||||||
generateRandomString
|
generateRandomString
|
||||||
@@ -84,7 +85,7 @@ function registerCredential({ username, secret }, { nickname }) {
|
|||||||
const clientData = rawCredential ? parseClientData(rawCredential) : null;
|
const clientData = rawCredential ? parseClientData(rawCredential) : null;
|
||||||
const publicKey = rawCredential ? parsePublicKeyFromAttestationData(rawCredential) : null;
|
const publicKey = rawCredential ? parsePublicKeyFromAttestationData(rawCredential) : null;
|
||||||
|
|
||||||
const challengeFromClientData = clientData && clientData.challenge ? atob(clientData.challenge) : null;
|
const challengeFromClientData = clientData && clientData.challenge ? base64decode(clientData.challenge) : null;
|
||||||
|
|
||||||
logger.debug('webauthn create raw response', rawCredential);
|
logger.debug('webauthn create raw response', rawCredential);
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ function verifyCredential({ username }, credentialId) {
|
|||||||
challenge: stringToArrayBuffer(challenge),
|
challenge: stringToArrayBuffer(challenge),
|
||||||
rpId: window.location.hostname
|
rpId: window.location.hostname
|
||||||
});
|
});
|
||||||
publicKeyCredentialRequestOptions.allowCredentials[0].id = stringToArrayBuffer(atob(credentialId));
|
publicKeyCredentialRequestOptions.allowCredentials[0].id = stringToArrayBuffer(base64decode(credentialId));
|
||||||
|
|
||||||
logger.debug('webauthn get options', publicKeyCredentialRequestOptions);
|
logger.debug('webauthn get options', publicKeyCredentialRequestOptions);
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ function verifyCredential({ username }, credentialId) {
|
|||||||
publicKey: publicKeyCredentialRequestOptions
|
publicKey: publicKeyCredentialRequestOptions
|
||||||
}).then(rawCredential => {
|
}).then(rawCredential => {
|
||||||
const clientData = rawCredential ? parseClientData(rawCredential) : null;
|
const clientData = rawCredential ? parseClientData(rawCredential) : null;
|
||||||
const challengeFromClientData = clientData && clientData.challenge ? atob(clientData.challenge) : null;
|
const challengeFromClientData = clientData && clientData.challenge ? base64decode(clientData.challenge) : null;
|
||||||
const userIdParts = rawCredential && rawCredential.response && rawCredential.response.userHandle ? arrayBufferToString(rawCredential.response.userHandle).split('|') : null;
|
const userIdParts = rawCredential && rawCredential.response && rawCredential.response.userHandle ? arrayBufferToString(rawCredential.response.userHandle).split('|') : null;
|
||||||
|
|
||||||
logger.debug('webauthn get raw response', rawCredential);
|
logger.debug('webauthn get raw response', rawCredential);
|
||||||
|
|||||||
Reference in New Issue
Block a user