Skip to content

Commit e0f3696

Browse files
Introduce DiscoverFromExternalSource activation + visibility requirements (#129)
1 parent 1d53712 commit e0f3696

File tree

2 files changed

+60
-19
lines changed

2 files changed

+60
-19
lines changed

explainer.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,35 @@ At its core, the API is designed for a website ("verifier") to [transparently](h
3434

3535
Here is an example of how the  the API might be used in practice:
3636

37+
The API needs to be initiated through a user gesture, such as a button click:
38+
39+
```html
40+
<button onclick="requestLicense()">Request Driver's license<button>
41+
```
42+
43+
3744
```javascript
38-
const digitalCredential = await navigator.identity.get({
39-
  digital: {
40-
    providers: [{
41-
      // Protocol extensibility:
42-
      protocol: "oid4vp",
43-
      // An example of an OpenID4VP request to wallets.
44-
      // Based on https://github.com/openid/OpenID4VP/issues/125
45-
      request: {
46-
        nonce: "n-0S6_WzA2Mj",
47-
        presentation_definition: {
48-
          // Presentation Exchange request, omitted for brevity
49-
        }
50-
      }
51-
    }],
52-
  },
53-
});
54-
// To be decrypted on the server...
55-
const encryptedData = digitalCredential.data;
45+
async function requestLicense() {
46+
const oid4pv = {
47+
// Protocol extensibility:
48+
protocol: "oid4vp", // An example of an OpenID4VP request to wallets. // Based on https://github.com/openid/OpenID4VP/issues/125
49+
request: {
50+
nonce: "n-0S6_WzA2Mj",
51+
presentation_definition: {
52+
// Presentation Exchange request, omitted for brevity
53+
},
54+
},
55+
};
56+
const digitalCredential = await navigator.identity.get({
57+
digital: {
58+
providers: [oid4pv],
59+
},
60+
});
61+
// To be decrypted on the server...
62+
const encryptedData = digitalCredential.data;
63+
}
5664
```
65+
5766
You can read a more detailed and technical description of the API in the [specification draft](https://wicg.github.io/digital-identities/).
5867

5968
### Using the API from another origin

index.html

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ <h2>
241241
{{DigitalCredential}} instances are [=Credential/origin bound=].
242242
</p>
243243
<h3>
244-
Extensions to Credential Management API
244+
Integration with Credential Management API
245245
</h3>
246246
<aside class="issue" data-number="65"></aside>
247247
<h3>
@@ -272,6 +272,38 @@ <h3>
272272
The <dfn data-dfn-for="DigitalCredential">data</dfn> member is the
273273
credential's response data.
274274
</p>
275+
<h3>
276+
[[\DiscoverFromExternalSource]](origin, options, sameOriginWithAncestors)
277+
internal method
278+
</h3>
279+
<p>
280+
When invoked, the <dfn class="export" data-dfn-for=
281+
"DigitalCredential">[[\DiscoverFromExternalSource]](origin, options,
282+
sameOriginWithAncestors)</dfn> internal method MUST:
283+
</p>
284+
<ol class="algorithm">
285+
<li>Let |global| be [=this=]'s [=relevant global object=].
286+
</li>
287+
<li>Let |document| be |global|'s [=associated `Document`=].
288+
</li>
289+
<li>If |document| is not a [=Document/fully active descendant of a
290+
top-level traversable with user attention=], [=exception/throw=]
291+
{{"NotAllowedError"}} {{DOMException}}.
292+
</li>
293+
<li>If |window| does not have [=transient activation=],
294+
[=exception/throw=] {{"NotAllowedError"}} {{DOMException}}.
295+
</li>
296+
<li>[=Consume user activation=] of |window|.
297+
</li>
298+
<li>
299+
<aside class="issue">
300+
Details of how to actually get the [=digital credential=] are
301+
forthcoming.
302+
</aside>
303+
</li>
304+
<li>Return a {{DigitalCredential}}.
305+
</li>
306+
</ol>
275307
<h3>
276308
[[\Store]](credential, sameOriginWithAncestors) internal method
277309
</h3>

0 commit comments

Comments
 (0)