Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('enrollWebauthnDevice', () => {
challenge,
excludeCredentials,
authenticatorAttachment: 'cross-platform',
hints: ['security-key'],
});

expect(navigator.credentials.create).to.have.been.calledWith({
Expand All @@ -85,8 +86,9 @@ describe('enrollWebauthnDevice', () => {
timeout: 800000,
attestation: 'none',
authenticatorSelection: {
authenticatorAttachment: 'cross-platform',
userVerification: 'discouraged',
authenticatorAttachment: 'cross-platform',
hints: ['security-key'],
},
excludeCredentials: [
{
Expand Down Expand Up @@ -132,12 +134,14 @@ describe('enrollWebauthnDevice', () => {
challenge,
excludeCredentials,
authenticatorAttachment: 'platform',
hints: ['client-device'],
});

expect(navigator.credentials.create).to.have.been.calledWithMatch({
publicKey: {
authenticatorSelection: {
authenticatorAttachment: 'platform',
hints: ['client-device'],
},
},
});
Expand Down
12 changes: 11 additions & 1 deletion app/javascript/packages/webauthn/enroll-webauthn-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface AuthenticatorAttestationResponseBrowserSupport
getAuthenticatorData: AuthenticatorAttestationResponse['getAuthenticatorData'] | undefined;
}

type PublicKeyCredentialHintType = 'client-device' | 'security-key' | 'hybrid';

interface EnrollOptions {
user: PublicKeyCredentialUserEntity;

Expand All @@ -23,6 +25,8 @@ interface EnrollOptions {
excludeCredentials: PublicKeyCredentialDescriptor[];

authenticatorAttachment?: AuthenticatorAttachment;

hints?: Array<PublicKeyCredentialHintType>;
}

interface EnrollResult {
Expand All @@ -37,6 +41,10 @@ interface EnrollResult {
transports?: string[];
}

interface AuthenticatorSelectionCriteriaWithHints extends AuthenticatorSelectionCriteria {
hints?: Array<PublicKeyCredentialHintType>;
}

/**
* All possible algorithms supported within the CBOR Object Signing and Encryption (COSE) format.
*
Expand Down Expand Up @@ -76,6 +84,7 @@ async function enrollWebauthnDevice({
challenge,
excludeCredentials,
authenticatorAttachment,
hints,
}: EnrollOptions): Promise<EnrollResult> {
const credential = (await navigator.credentials.create({
publicKey: {
Expand All @@ -89,7 +98,8 @@ async function enrollWebauthnDevice({
// Prevents user from needing to use PIN with Security Key
userVerification: 'discouraged',
authenticatorAttachment,
},
hints,
} as AuthenticatorSelectionCriteriaWithHints,
excludeCredentials,
},
})) as PublicKeyCredential;
Expand Down
1 change: 1 addition & 0 deletions app/javascript/packs/webauthn-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function webauthn() {
.filter(Boolean),
),
authenticatorAttachment: platformAuthenticator ? 'platform' : 'cross-platform',
hints: platformAuthenticator ? ['client-device', 'hybrid'] : ['security-key'],
})
.then((result) => {
(document.getElementById('webauthn_id') as HTMLInputElement).value = result.webauthnId;
Expand Down