Initial commit - version 1.0.0

This commit is contained in:
2023-05-27 10:00:18 -04:00
commit fe6531c8ec
15 changed files with 8795 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import base64url from "base64url";
export const loginHandler = (event) => {
if (!window.PublicKeyCredential) { return; }
event.preventDefault();
return fetch('/login/public-key/challenge', {
method: 'POST',
headers: {
'Accept': 'application/json'
}
})
.then((response) => {
return response.json();
})
.then((json) => {
return navigator.credentials.get({
publicKey: {
challenge: base64url.decode(json.challenge),
//allowCredentials: [
// { type: 'public-key', id: base64url.decode('VjXl8fuJXIAqLg-BVrR5oeLLfee6gBGKXdMxo6xtMySugJfU2HNvTJk84T1DgFYtJDpDrwL2Bg_QM4xQwVAutA') },
// { type: 'public-key', id: base64url.decode('noMuGuaaVLubAVjuS6Z2BYrrBpajYhtjnFgvSjk0IV1LJeVrupbpnw') }
//]
}
});
})
.then((credential) => {
var body = {
id: credential.id,
response: {
clientDataJSON: base64url.encode(credential.response.clientDataJSON),
authenticatorData: base64url.encode(credential.response.authenticatorData),
signature: base64url.encode(credential.response.signature),
userHandle: credential.response.userHandle ? base64url.encode(credential.response.userHandle) : null
}
};
if (credential.authenticatorAttachment) {
body.authenticatorAttachment = credential.authenticatorAttachment;
}
return fetch('/login/public-key', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(body)
});
})
.then((response) => {
return response.json();
})
.then((json) => {
window.location.href = json.location;
})
.catch((error) => {
console.log(error);
});
});
};

View File

View File

@@ -0,0 +1,41 @@
import base64url from 'base64url';
interface Credentials {
challenge: string;
user: {
displayName: string;
id: string;
name: string;
};
}
export const createCredentials = ({ challenge, user: { id, name, displayName } }: Credentials) =>
// https://chromium.googlesource.com/chromium/src/+/master/content/browser/webauth/uv_preferred.md
navigator.credentials.create({
publicKey: {
rp: {
name: 'Todos',
},
user: {
id: base64url.toBuffer(id),
name,
displayName,
},
challenge: base64url.toBuffer(challenge),
pubKeyCredParams: [
{
type: 'public-key',
alg: -7, // "ES256" IANA COSE Algorithms registry
}
],
//attestation: 'none',
authenticatorSelection: {
userVerification: 'discouraged',
//authenticatorAttachment: "platform",
residentKey: 'required',
},
//extensions: {
// credProps: true
//}
},
});