Fixed webauthn two factor authentication

This commit is contained in:
Jan Böhmer 2023-06-11 13:14:45 +02:00
parent 624696711d
commit b7573a40d7
3 changed files with 55 additions and 42 deletions

View file

@ -21,8 +21,13 @@
class WebauthnTFA {
// Decodes a Base64Url string
_base64UrlDecode = (input) => {
_b64UrlSafeEncode = (str) => {
const b64 = btoa(str);
return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
}
// Decodes a Base64Url string
_b64UrlSafeDecode = (input) => {
input = input
.replace(/-/g, '+')
.replace(/_/g, '/');
@ -39,13 +44,16 @@ class WebauthnTFA {
};
// Converts an array of bytes into a Base64Url string
_arrayToBase64String = (a) => btoa(String.fromCharCode(...a));
_arrayToBase64String = (a) => {
const str = String.fromCharCode(...a);
return this._b64UrlSafeEncode(str);
}
// Prepares the public key options object returned by the Webauthn Framework
_preparePublicKeyOptions = publicKey => {
//Convert challenge from Base64Url string to Uint8Array
publicKey.challenge = Uint8Array.from(
this._base64UrlDecode(publicKey.challenge),
this._b64UrlSafeDecode(publicKey.challenge),
c => c.charCodeAt(0)
);
@ -67,7 +75,7 @@ class WebauthnTFA {
return {
...data,
id: Uint8Array.from(
this._base64UrlDecode(data.id),
this._b64UrlSafeDecode(data.id),
c => c.charCodeAt(0)
),
};
@ -81,7 +89,7 @@ class WebauthnTFA {
return {
...data,
id: Uint8Array.from(
this._base64UrlDecode(data.id),
this._b64UrlSafeDecode(data.id),
c => c.charCodeAt(0)
),
};