3

I am implementing webauthn using PHP, now I'm facing problem with how to detect browser is public-key credentials supported or not. If browser is supported public-key credentials then I have to start fingerprint registration procedure.

So is there any way we can detect browser public-key credentials.

Sachin
  • 789
  • 5
  • 18

2 Answers2

7
 if (typeof(PublicKeyCredential) != "undefined") {
   // Code here
 }

The PublicKeyCredential interface provides information about a public key / private key pair. It inherits from Credential, and was created by the Web Authentication API extension to the Credential Management API. Other interfaces that inherit from Credential are PasswordCredential and FederatedCredential.

https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential

grzuy
  • 4,791
  • 2
  • 20
  • 17
  • I have used this `if (window.PasswordCredential) {` condition. Inside this condition, I use this `navigator.credentials.get(` still, I can see some of the user's browsers report this error: `The user agent does not support public key credentials`. what could be the reason? Should I check for both PasswordCredential and PublicKeyCredential like this `if (window.PasswordCredential && typeof(PublicKeyCredential) != undefined)) {` – Gideon Babu Mar 24 '20 at 12:25
3

I found one Google developer article and this JavaScript code work for me.

if (window.PublicKeyCredential) {
   // code here
}else{
   alert("public-key credentials not supported");
}

https://developers.google.com/web/updates/2018/03/webauthn-credential-management

Sachin
  • 789
  • 5
  • 18