files/en-us/web/api/publickeycredentialcreationoptions/index.md
{{APIRef("Web Authentication API")}}{{securecontext_header}}
The PublicKeyCredentialCreationOptions dictionary represents the object passed to {{domxref("CredentialsContainer.create()")}} as the value of the publicKey option: that is, when using create() to create a public key credential using the Web Authentication API.
attestation {{optional_inline}}
: A string specifying the relying party's preference for how the attestation statement (i.e., provision of verifiable evidence of the authenticity of the authenticator and its data) is conveyed during credential creation. The value can be one of the following:
"none"
"none" is chosen as the attestation value, and the authenticator signals that it uses a CA to generate its attestation statement, the client app will replace it with a "None" attestation statement, indicating that no attestation statement is available."direct"
"enterprise"
"indirect"
If attestation is omitted, it will default to "none".
attestationFormats {{optional_inline}}
: An array of strings specifying the relying party's preference for the attestation statement format used by the authenticator. Values should be ordered from highest to lowest preference, and should be considered hints — the authenticator may choose to issue an attestation statement in a different format. For a list of valid formats, see WebAuthn Attestation Statement Format Identifiers.
If omitted, attestationFormats defaults to an empty array.
authenticatorSelection {{optional_inline}}
authenticatorAttachment {{optional_inline}}
"platform"
"cross-platform"
: The authenticator is not a part of the device WebAuthn is running on (termed a roaming authenticator as it can roam between different devices), therefore WebAuthn will communicate with it using a cross-platform transport protocol such as Bluetooth or NFC. A public key credential bound to a roaming authenticator is called a roaming credential.
If omitted, any type of authenticator, either platform or cross-platform, can be selected for the credential creation operation.
requireResidentKey {{optional_inline}}
: A boolean. If set to true, it indicates that the relying party wants to create a discoverable credential.
This option is retained only for backwards compatibility: callers should use the residentKey option instead. If residentKey is given and is supported, then requireResidentKey is ignored. The requireResidentKey option should be set to true if and only if residentKey is set to "required".
Defaults to false.
residentKey {{optional_inline}}
: A string that specifies the extent to which the relying party wants to create a discoverable credential. Possible values are:
"discouraged"
"preferred"
userVerification setting."required"
NotAllowedError {{domxref("DOMException")}} is thrown. See the create() exceptions list for more details.If omitted, residentKey defaults to "required" if requireResidentKey is true, otherwise the default value is "discouraged".
userVerification {{optional_inline}}
: A string that specifies the relying party's requirements for user verification for the create() operation. Possible values are:
"discouraged"
create() operation, in the interests of minimizing disruption to the user experience."preferred"
create() operation, but it will not fail if user verification cannot be performed."required"
create() operation — if user verification cannot be performed, an error is thrown.If omitted, userVerification defaults to "preferred".
challenge
excludeCredentials {{optional_inline}}
: An {{jsxref("Array")}} of objects describing existing credentials that are already mapped to this user account (as identified by user.id). This is provided by the relying party, and checked by the user agent to avoid creating a new public key credential on an authenticator that already has a credential mapped to the specified user account. Each item should be of the form:
id
transports {{optional_inline}}
"ble", "hybrid", "internal", "nfc", and "usb" (see {{domxref("AuthenticatorAttestationResponse.getTransports", "getTransports()")}} for more details).type
"public-key", but more values may be added in the future.If the create() call is attempting to create a duplicate public key credential on an authenticator, the user agent will guide to user to create the credential using a different authenticator, or fail if that is not possible.
If excludeCredentials is omitted, it defaults to an empty array.
extensions {{optional_inline}}
: An object containing properties representing the input values for any requested extensions. These extensions are used to specific additional processing by the client or authenticator during the credential creation process. Examples include specifying whether a returned credential is discoverable, or whether the relying party will be able to store large blob data associated with a credential.
Extensions are optional and different browsers may recognize different extensions. Processing extensions is always optional for the client: if a browser does not recognize a given extension, it will just ignore it. For information on using extensions, and which ones are supported by which browsers, see Web Authentication extensions.
hints {{optional_inline}} {{experimental_inline}}
: An array of strings providing hints as to what UI the browser should provide for the user to create a public key credential.
The strings can be any of the following:
"security-key"
"client-device"
authenticatorAttachment platform value."hybrid"
The authenticatorAttachment cross-platform value is essentially a combination of the hints option security-key and hybrid values — if a device doesn't have bluetooth and an RP specifies attachment: "cross-platform", the resulting UI will likely be similar to the hints: "security-key" UI.
When multiple strings are included in the array, their order denotes the order of preference, from high to low. Supporting browsers that respect the hints should use the first one that they understand.
The hints option provides a more flexible way to specify UI preferences for creating a credential than the authenticatorAttachment option, which completely hides the non-chosen option. hints also allow indicating a preference for either security keys or hybrid, which is not possible to do with authenticatorAttachment.
Specified hints may contradict hints provided in the authenticatorAttachment option. When the provided hints contradict this option, the hints take precedence. hints may also be ignored by the browser under specific circumstances, for example if a hinted authenticator type is not usable on the user's device.
For some specific code and UI examples, see Introducing hints, Related Origin Requests and JSON serialization for WebAuthn in Chrome.
pubKeyCredParams
: An {{jsxref("Array")}} of objects which specify the key types and signature algorithms the Relying Party supports, ordered from most preferred to least preferred. The client and authenticator will make a best-effort to create a credential of the most preferred type possible. These objects will contain the following properties:
alg
-8: EdDSA-7: ES256-257: RS256type
"public-key", but more values may be added in the future.If none of the listed credential types can be created, the create() operation fails.
rp
id {{optional_inline}}
: A string representing the ID of the relying party. A public key credential can only be used for authentication with the same relying party (as identified by the publicKey.rpId in a {{domxref("CredentialsContainer.get()", "navigator.credentials.get()")}} call) it was registered with — the IDs need to match.
The id cannot include a port or scheme like a standard origin, but the domain scheme must be https scheme. The id needs to equal the origin's effective domain, or a domain suffix thereof. So for example if the relying party's origin is https://login.example.com:1337, the following ids are valid:
login.example.comexample.comBut not:
m.login.example.comcomIf omitted, id defaults to the document origin — which would be login.example.com in the above example.
name
"Facebook"). This is the name the user will be presented with when creating or validating a WebAuthn operation.timeout {{optional_inline}}
user
displayName
"Maria Sanchez"), which will have been set by user during initial registration with the relying party.id
name
displayNames. This could be an email address (such as "[email protected]"), phone number (for example "+12345678901"), or some other kind of user account identifier (for example "ElainaSanchez667").This example creates a PublicKeyCredentialCreationOptions, specifying only the required properties, and using defaults for the rest.
It then passes the object into navigator.credentials.create(), to create a new public key credential.
const publicKey = {
challenge: challengeFromServer,
rp: { id: "acme.com", name: "ACME Corporation" },
user: {
id: new Uint8Array([79, 252, 83, 72, 214, 7, 89, 26]),
name: "jamiedoe",
displayName: "Jamie Doe",
},
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
};
const publicKeyCredential = await navigator.credentials.create({ publicKey });
A successful create() call returns a promise that resolves with a {{domxref("PublicKeyCredential")}} object instance, representing a public key credential that can later be used to authenticate a user via a WebAuthn {{domxref("CredentialsContainer.get()", "get()")}} call. Its {{domxref("PublicKeyCredential.response")}} property contains an {{domxref("AuthenticatorAttestationResponse")}} object providing access to several useful pieces of information including the authenticator data, public key, transport mechanisms, and more.
navigator.credentials.create({ publicKey }).then((publicKeyCredential) => {
const response = publicKeyCredential.response;
// Access attestationObject ArrayBuffer
const attestationObj = response.attestationObject;
// Access client JSON
const clientJSON = response.clientDataJSON;
// Return authenticator data ArrayBuffer
const authenticatorData = response.getAuthenticatorData();
// Return public key ArrayBuffer
const pk = response.getPublicKey();
// Return public key algorithm identifier
const pkAlgo = response.getPublicKeyAlgorithm();
// Return permissible transports array
const transports = response.getTransports();
});
Some of this data will need to be stored on the server for future authentication operations against this credential — for example the public key, the algorithm used, and the permissible transports.
See Creating a key pair and registering a user for more information about how the overall flow works.
{{Specifications}}
{{Compat}}