42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
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
|
|
//}
|
|
},
|
|
});
|