-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
73 lines (57 loc) · 1.69 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
title: "PublicKeyCredential: id property"
short-title: id
slug: Web/API/PublicKeyCredential/id
page-type: web-api-instance-property
browser-compat: api.PublicKeyCredential.id
---
{{APIRef("Web Authentication API")}}{{securecontext_header}}
The **`id`** read-only property of the
{{domxref("PublicKeyCredential")}} interface is a string, inherited
from {{domxref("Credential")}}, which represents the identifier of the current
`PublicKeyCredential` instance.
This property is a [base64url encoded](/en-US/docs/Glossary/Base64) version of {{domxref("PublicKeyCredential.rawId")}}.
> [!NOTE]
> This property may only be used in top-level contexts and will
> not be available in an {{HTMLElement("iframe")}} for example.
## Value
A string being the [base64url encoded](/en-US/docs/Glossary/Base64) version of {{domxref("PublicKeyCredential.rawId")}}.
## Examples
```js
const publicKey = {
challenge: new Uint8Array(26) /* this actually is given from the server */,
rp: {
name: "Example CORP",
id: "login.example.com",
},
user: {
id: new Uint8Array(26) /* To be changed for each user */,
name: "canand@example.com",
displayName: "Carina Anand",
},
pubKeyCredParams: [
{
type: "public-key",
alg: -7,
},
],
};
navigator.credentials
.create({ publicKey })
.then((newCredentialInfo) => {
const id = newCredentialInfo.id;
// Do something with the id
// send attestation response and client extensions
// to the server to proceed with the registration
// of the credential
})
.catch((err) => {
console.error(err);
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Credential.id")}}