Skip to content

Commit

Permalink
Add a supported() function to test WebAuthn support.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Aug 9, 2019
1 parent dd160de commit 7c116d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
export {
create,
get,
supported,
} from "./webauthn";
export {
schema,
Expand Down
14 changes: 14 additions & 0 deletions src/webauthn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ export async function get(requestJSON: CredentialRequestOptionsJSON): Promise<Pu
const response = (await navigator.credentials.get(request)) as PublicKeyCredential;
return convert(bufferToBase64url, publicKeyCredentialWithAssertion, response);
}

declare global {
interface Window {
PublicKeyCredential: any | undefined;
}
}

// This function does a simple check to test for the credential management API
// functions we need, and an indication of public credential authentication
// support.
// https://developers.google.com/web/updates/2018/03/webauthn-credential-management
export function supported(): boolean {
return !!(navigator.credentials && navigator.credentials.create && navigator.credentials.get && window.PublicKeyCredential);
}

0 comments on commit 7c116d2

Please sign in to comment.