PublicKeyCredential
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The PublicKeyCredential interface provides information about a public key / private key pair, which is a credential for logging in to a service using an un-phishable and data-breach resistant asymmetric key pair instead of a password. 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.
Note: This API is restricted to top-level contexts. Use from within an <iframe> element will not have any effect.
Properties
-
PublicKeyCredential.typeRead only Secure context -
Inherited from
Credential. Always set topublic-keyforPublicKeyCredentialinstances. -
PublicKeyCredential.idRead only Secure context -
Inherited from
Credentialand overridden to be the base64url encoding ofPublicKeyCredential.rawId. -
PublicKeyCredential.rawIdRead only Secure context -
An
ArrayBufferthat holds the globally unique identifier for thisPublicKeyCredential. This identifier can be used to look up credentials for future calls toCredentialsContainer.get. -
PublicKeyCredential.responseRead only Secure context -
An instance of an
AuthenticatorResponseobject. It is either of typeAuthenticatorAttestationResponseif thePublicKeyCredentialwas the results of anavigator.credentials.create()call, or of typeAuthenticatorAssertionResponseif thePublicKeyCredentialwas the result of anavigator.credentials.get()call.
Methods
-
PublicKeyCredential.getClientExtensionResults()Secure context -
If any extensions were requested, this method will return the results of processing those extensions.
-
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()Secure context -
A static method returning a
Promisewhich resolves totrueif an authenticator bound to the platform is capable of verifying the user.
Examples
Creating a new instance of PublicKeyCredential
Here, we use navigator.credentials.create() to generate a new credential.
var publicKey = { challenge: /* from the server */, rp: { name: "Example CORP", id : "login.example.com" }, user: { id: new Uint8Array(16), name: "[email protected]", displayName: "John Doe" }, pubKeyCredParams: [ { type: "public-key", alg: -7 } ] }; navigator.credentials.create({ publicKey }) .then(function (newCredentialInfo) { var response = newCredentialInfo.response; var clientExtensionsResults = newCredentialInfo.getClientExtensionResults(); }).catch(function (err) { console.error(err); });
Getting an existing instance of PublicKeyCredential
Here, we fetch an existing credential from an authenticator, using navigator.credentials.get().
var options = { challenge: new Uint8Array([/* bytes sent from the server */]) }; navigator.credentials.get({ "publicKey": options }) .then(function (credentialInfoAssertion) { // send assertion response back to the server // to proceed with the control of the credential }).catch(function (err) { console.error(err); });
Specifications
| Specification |
|---|
| Web Authentication: An API for accessing Public Key Credentials - Level 3 (Web Authentication) # iface-pkcredential |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
PublicKeyCredential |
67 |
18 |
60
Only supports USB U2F tokens.
|
No |
No |
13 |
No |
70 |
60
Only supports USB U2F tokens.
|
No |
13 |
No |
getClientExtensionResults |
67 |
18 |
60
Only supports USB U2F tokens.
|
No |
No |
13 |
No |
70 |
60
Only supports USB U2F tokens.
|
No |
13 |
No |
isUserVerifyingPlatformAuthenticatorAvailable |
67 |
18 |
60
Only supports USB U2F tokens.
|
No |
No |
13 |
No |
70 |
60
Only supports USB U2F tokens.
|
No |
13 |
No |
rawId |
67 |
18 |
60
Only supports USB U2F tokens.
|
No |
No |
13 |
No |
70 |
60
Only supports USB U2F tokens.
|
No |
13 |
No |
response |
67 |
18 |
60
Only supports USB U2F tokens.
|
No |
No |
13 |
No |
70 |
60
Only supports USB U2F tokens.
|
No |
13 |
No |
See also
- The parent interface
Credential
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential