Secure contextThis 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.type
Read only Secure context- Inherited from
Credential
. Always set topublic-key
forPublicKeyCredential
instances. PublicKeyCredential.id
Read only Secure context- Inherited from
Credential
and overridden to be the base64url encoding ofPublicKeyCredential.rawId
. PublicKeyCredential.rawId
Read only Secure context- An
ArrayBuffer
that holds the globally unique identifier for thisPublicKeyCredential
. This identifier can be used to look up credentials for future calls toCredentialsContainer.get
. PublicKeyCredential.response
Read only Secure context- An instance of an
AuthenticatorResponse
object. It is either of typeAuthenticatorAttestationResponse
if thePublicKeyCredential
was the results of anavigator.credentials.create()
call, or of typeAuthenticatorAssertionResponse
if thePublicKeyCredential
was 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
Promise
which resolves totrue
if an authenticator bound to the platform is capable of verifying the user. With the current state of implementation, this method only resolves totrue
when Windows Hello is available on the system.
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 | Status | Comment |
---|---|---|
Web Authentication: An API for accessing Public Key Credentials Level 1The definition of 'PublicKeyCredential interface' in that specification. | Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
PublicKeyCredential
|
Chrome Full support 67 Full support 67 Full support 65 Notes' Only supports USB U2F tokens.
Disabled' From version 65: this feature is behind the |
Edge
Full support 18 |
Firefox Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
IE
No support No |
Opera
No support No |
Safari
Full support 13 |
WebView Android
Full support 70 |
Chrome Android
Full support 70 |
Firefox Android Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
Opera Android
No support No |
Safari iOS
Full support 13.3 |
Samsung Internet Android
No support No |
getClientExtensionResults
|
Chrome Full support 67 Full support 67 Full support 65 Notes' Only supports USB U2F tokens.
Disabled' From version 65: this feature is behind the |
Edge
Full support 18 |
Firefox Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
IE
No support No |
Opera
No support No |
Safari
Full support 13 |
WebView Android
Full support 70 |
Chrome Android
Full support 70 |
Firefox Android Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
Opera Android
No support No |
Safari iOS
Full support 13.3 |
Samsung Internet Android
No support No |
isUserVerifyingPlatformAuthenticatorAvailable
|
Chrome Full support 67 Full support 67 Full support 65 Notes' Only supports USB U2F tokens.
Disabled' From version 65: this feature is behind the |
Edge
Full support 18 |
Firefox Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
IE
No support No |
Opera
No support No |
Safari
Full support 13 |
WebView Android
Full support 70 |
Chrome Android
Full support 70 |
Firefox Android Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
Opera Android
No support No |
Safari iOS
Full support 13.3 |
Samsung Internet Android
No support No |
rawId
|
Chrome Full support 67 Full support 67 Full support 65 Notes' Only supports USB U2F tokens.
Disabled' From version 65: this feature is behind the |
Edge
Full support 18 |
Firefox Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
IE
No support No |
Opera
No support No |
Safari
Full support 13 |
WebView Android
Full support 70 |
Chrome Android
Full support 70 |
Firefox Android Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
Opera Android
No support No |
Safari iOS
Full support 13.3 |
Samsung Internet Android
No support No |
response
|
Chrome Full support 67 Full support 67 Full support 65 Notes' Only supports USB U2F tokens.
Disabled' From version 65: this feature is behind the |
Edge
Full support 18 |
Firefox Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
IE
No support No |
Opera
No support No |
Safari
Full support 13 |
WebView Android
Full support 70 |
Chrome Android
Full support 70 |
Firefox Android Full support 60 Full support 60 Notes' Only supports USB U2F tokens. |
Opera Android
No support No |
Safari iOS
Full support 13.3 |
Samsung Internet Android
No support No |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
See also
- The parent interface
Credential
PublicKeyCredential by Mozilla Contributors is licensed under CC-BY-SA 2.5.