-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.bs
2551 lines (1980 loc) · 129 KB
/
index.bs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<h1>Credential Management Level 1</h1>
<pre class="metadata">
Status: ED
ED: https://w3c.github.io/webappsec-credential-management/
TR: https://www.w3.org/TR/credential-management-1/
Previous Version: https://www.w3.org/TR/2016/WD-credential-management-1-20160425/
Shortname: credential-management
Level: 1
Former Editor: Jeff Hodges, w3cid 43843, Google Inc., [email protected]
Editor: Nina Satragno, w3cid 116344, Google Inc., [email protected]
Editor: Marcos Cáceres, w3cid 39125, Apple Inc., [email protected]
Former Editor: Mike West 56384, Google Inc., [email protected]
Group: webappsec
Abstract:
This specification describes an imperative API enabling a website to request a
user's credentials from a user agent, and to help the user agent correctly
store user credentials for future use.
Indent: 2
Version History: https://github.com/w3c/webappsec-credential-management/commits/main/index.src.html
Issue Tracking: GitHub https://github.com/w3c/webappsec-credential-management/issues
Boilerplate: omit conformance, omit feedback-header
!Participate: <a href="https://github.com/w3c/webappsec-credential-management/issues/new">File an issue</a> (<a href="https://github.com/w3c/webappsec-credential-management/issues">open issues</a>)
Markup Shorthands: css off, markdown on
</pre>
<pre class="anchors">
spec: ECMA262; urlPrefix: https://tc39.github.io/ecma262/
type: dfn
text: JavaScript realm; url: sec-code-realms
text: internal method; url: sec-ordinary-object-internal-methods-and-internal-slots
spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
urlPrefix: forms.html
type: element-attr
text: autocomplete; for: input; url: #attr-fe-autocomplete
text: name; for: input; url: #attr-fe-name
text: enctype; for: form; url: #concept-fs-enctype
type: attr-value
for: autocomplete
text: current-password; url: attr-fe-autocomplete-current-password
text: new-password; url: attr-fe-autocomplete-new-password
text: nickname; url: attr-fe-autocomplete-nickname
text: name; url: attr-fe-autocomplete-name
text: photo; url: attr-fe-autocomplete-photo
text: username; url: attr-fe-autocomplete-username
urlPrefix: origin.html
type: dfn
text: origin; for: html-origin-def; url: concept-origin
urlPrefix: browsers.html
type: dfn
text: browsing context; for: document; url: concept-document-bc
urlPrefix: webappapis.html
type: dfn
text: DOM manipulation task source; url: dom-manipulation-task-source
spec: XHR; urlPrefix: https://xhr.spec.whatwg.org/
type: dfn
text: entry; url: concept-formdata-entry
text: entries; for: FormData; url: concept-formdata-entry
text: name; for: entry; url: concept-formdata-entry-name
text: value; for: entry; url: concept-formdata-entry-value
text: type; for: entry; url: concept-formdata-entry-type
type: interface
text: FormData; url: interface-formdata
spec: PSL; urlPrefix: https://publicsuffix.org/list/
type: dfn
text: registerable domain; url: #
text: public suffix; url: #
spec: FETCH; urlPrefix: https://fetch.spec.whatwg.org/
type: dfn
text: http-network-or-cache fetch; url: http-network-or-cache-fetch
spec: promises-guide-1; urlPrefix: https://www.w3.org/2001/tag/doc/promises-guide
type: dfn
text: promise-calling; url: should-promise-call
spec: web-otp; urlPrefix: https://wicg.github.io/web-otp
type: interface
text: OTPCredential; url: otpcredential
</pre>
<pre class="link-defaults">
spec:html; type:dfn; for:html-origin-def; text:origin
spec:html; type:dfn; for:environment settings object; text:global object
spec:fetch; type:dfn; for:/; text:request
spec:fetch; type:dictionary; for:/; text:RequestInit
spec:infra; type:dfn; for:/; text:set
spec:infra; type:dfn; for:struct; text:item
spec:webidl; type:idl; for:/; text:Function
spec:webidl; type:dfn; text:identifier
spec:webidl; type:interface; text:Promise
spec:webidl; type:dfn; text:resolve
<!-- These need to be exported -->
spec:html; type:dfn; text:submittable element
spec:html; type:dfn; text:form owner
spec:html; type:dfn; text:autofill detail tokens
spec:url; type:dfn; text:urlencoded byte serializer
</pre>
<pre class='ignored-specs'>
spec:css-syntax-3;
</pre>
<pre class="biblio">
{
"WEB-LOGIN": {
"authors": [ "Jason Denizac", "Robin Berjon", "Anne van Kesteren" ],
"href": "https://github.com/jden/web-login",
"title": "web-login"
},
"DIGITAL-CREDENTIALS": {
"authors": [ "Marcos Cáceres", "Sam Goto" ],
"href": "https://wicg.github.io/digital-credentials/",
"title": "Digital Credentials"
}
}
</pre>
<!--
████ ██ ██ ████████ ████████ ███████
██ ███ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ████████ ██ ██
██ ██ ████ ██ ██ ██ ██ ██
██ ██ ███ ██ ██ ██ ██ ██
████ ██ ██ ██ ██ ██ ███████
-->
<section>
# Introduction # {#introduction}
<em>This section is not normative.</em>
Signing into websites is more difficult than it should be. The user agent is in a unique position
to improve the experience in a number of ways, and most modern user agents have recognized this by
providing some measure of <i>credential management</i> natively in the browser. For example, users can save usernames
and passwords for websites; those [=credentials=] are later autofilled into sign-in forms, albeit with
varying degrees of success.
The <{input/autocomplete}> attribute offers a declarative mechanism by which websites can work
with user agents to improve the latter's ability to detect and fill sign-in forms by marking
specific fields as "username" or "password", and user agents implement a wide variety of detection
heuristics to work with websites which haven't taken the time to provide this detail in markup.
While this combination of heuristic and declarative detection works relatively well, the status
quo leaves some large gaps where detection is problematic. Sites with uncommon sign-in
mechanisms (submitting credentials via {{XMLHttpRequest}} [[XMLHTTPREQUEST]], for instance) are
difficult to reliably detect, as is the increasingly common case in which users wish to
authenticate themselves using a federated identity provider. Allowing websites to more directly
interact with the user agent's credential manager would allow the credential manager to be more
accurate on the one hand, and to assist users with federated sign-in on the other.
These use cases are explored in more detail in [[#use-cases]] and in
<a href="https://w3c.github.io/webappsec/usecases/credentialmanagement/">Credential Management:
Use Cases and Requirements</a>; this specification attempts to address many of the requirements
that document outlines by defining a Credential Manager API which a website can use to request
[=credentials=] for a user, and to ask the user agent to persist credentials when a user signs in
successfully.
Note: The API defined here is intentionally small and simple: it does not intend to provide
authentication in and of itself, but is limited to providing an interface to the existing
credential managers implemented by existing user agents. That functionality is valuable
<em>right now</em>, without significant effort on the part of either vendors or authors. There's
certainly quite a bit more which could be done, of course. See [[#teh-futur]] for some thoughts
we've punted for now, but which could be explored in future iterations of this API.
## Use Cases ## {#use-cases}
Modern user agents generally offer users the capability to save passwords when signing into a
website, and likewise offer the capability to fill those passwords into sign-in forms fully- or
semi-automatically when users return to a website. From the perspective of a website, this
behavior is completely invisible: the website doesn't know that passwords have been stored, and
it isn't notified that passwords have been filled. This is both good and bad. On the one hand, a
user agent's password manager works regardless of whether or not a site cooperates, which is
excellent for users. On the other, the password managers' behaviors are a fragile and proprietary
hodgepodge of heuristics meant to detect and fill sign-in forms, password change forms, etc.
A few problems with the status quo stand out as being particularly noteworthy:
* User agents have an incredibly difficult time helping users with
federated identity providers. While detecting a username/password
form submission is fairly straightforward, detecting sign-in via a
third-party is quite difficult to reliably do well. It would be nice
if a website could help the user agent understand the intent behind the
redirects associated with a typical federated sign-in action.
* Likewise, user agents struggle to detect more esoteric sign-in
mechanisms than simple username/password forms. Authors increasingly
asynchronously sign users in via {{XMLHttpRequest}} or similar
mechanisms in order to improve the experience and take more control over
the presentation. This is good for users, but tough for user agents to
integrate into their password managers. It would be nice if a website
could help the user agent make sense of the sign-in mechanism they
choose to use.
* Finally, changing passwords is less well-supported than it could be if
the website explicitly informed the user agent that credentials had
changed.
</section>
<!--
██████ ███████ ████████ ████████ ███ ████████ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ████████ ██████ ██ ██ ████████ ██
██ ██ ██ ██ ██ ██ █████████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ██ ██ ████████ ██ ██ ██ ████
-->
<section>
# Core API # {#core}
From a developer's perspective, a <dfn export id="concept-credential">credential</dfn> is an
object which allows a developer to make an authentication decision for a particular action. This
section defines a generic and extensible {{Credential}} interface which serves as a base class
for [=credentials=] defined in this and other documents, along with a set of APIs
hanging off of {{CredentialsContainer|navigator.credentials.*}} which enable developers to
obtain them.
Various [=credential type registry/credential types=] are each represented to JavaScript as an interface which
[=interface/inherits=], either directly or indirectly, from the {{Credential}} interface. This
document defines two such interfaces, {{PasswordCredential}} and {{FederatedCredential}}. Other
specifications, for example [[WEBAUTHN]], define other credential types.
A [=credential=] is <dfn export for="credential">effective</dfn> for a particular [=origin=] if it
is accepted as authentication on that origin. Even if a credential is effective at a particular
point in time, the UA can't assume that the same credential will be effective at any future time,
for a couple reasons:
1. A password credential may stop being effective if the account holder changes their password.
2. A credential made from a token received over SMS is likely to only be effective for a single
use.
Single-use [=credentials=] are generated by a <dfn export>credential source</dfn>, which could be
a private key, access to a federated account, the ability to receive SMS messages at a particular
phone number, or something else. Credential sources are not exposed to Javascript or explicitly
represented in this specification. To unify the model, we consider a password to be a credential
source on its own, which is simply copied to create password credentials.
Even though the UA can't assume that an effective credential will still be effective if used a
second time, or that a credential source that has generated an effective credential will be able
to generate a second effective credential in the future, the second is more likely than the first.
By recording (with {{CredentialsContainer/store()}}) which credentials have been effective in the
past, the UA has a better chance of [offering](#user-mediated-selection) effective credential
sources to the user in the future.
## Infrastructure ## {#core-infrastructure}
User agents MUST internally provide a <dfn export id="concept-credential-store">credential
store</dfn>, which is a vendor-specific, opaque storage mechanism to record which [=credentials=]
have been [=effective=]. It offers the following capabilities for [=credential=] access and
persistence:
1. <dfn for="credential store" abstract-op export>Store a credential</dfn> for later retrieval.
This accepts a [=credential=], and inserts it into the [=credential store=].
2. <dfn for="credential store" abstract-op export>Retrieve a list of credentials</dfn>. This
accepts an arbitrary filter, and returns a set of [=credentials=] that match the filter.
3. <dfn for="credential store" abstract-op export>Modify a credential</dfn>. This accepts a
[=credential=], and overwrites the state of an existing [=credential=] in the
[=credential store=].
Additionally, the [=credential store=] should maintain a <dfn for="origin">`prevent silent
access` flag</dfn> for [=origins=] (which is set to `true` unless otherwise specified).
An origin <dfn for="origin">requires user mediation</dfn> if its flag is set to `true`.
Note: The importance of user mediation is discussed in more detail in [[#user-mediation]].
Note: The [=credential store=] is an internal implementation detail of a user agent's
implementation of the API specified in this document, and is not exposed to the web directly.
More capabilities may be specified by other documents in support of specific [=credential=]
types.
This document depends on the Infra Standard for a number of foundational concepts used in its
algorithms and prose [[!INFRA]].
Each [=/environment settings object=] has an associated <dfn noexport>active credential
types</dfn>, a [=set=] which is initially empty.
### Infrastructure Algorithms ### {#sctn-infra-algorithms}
<!-- NOTE: '<h4>' maps to the same heading level as three hashs '###', thus using '<h5>' for the next section -->
<h5 id="algorithm-same-origin-with-ancestors" algorithm>Same-Origin with its Ancestors</h5>
An [=environment settings object=] (|settings|) is <dfn noexport>same-origin with its
ancestors</dfn> if the following algorithm returns `true`:
<ol class="algorithm">
1. If |settings|'s [=relevant global object=] has no [=associated Document=],
return `false`.
2. Let |document| be |settings|' [=relevant global object=]'s [=associated Document=].
3. If |document| has no [=document/browsing context=], return `false`.
4. Let |origin| be |settings|' [=environment settings object/origin=].
5. Let |navigable| be |document|'s [=node navigable=].
6. While |navigable| has a non-null [=navigable/parent=]:
1. Set |navigable| to |navigable|'s [=navigable/parent=].
2. If |navigable|'s [=active document=]'s [=origin=] is not [=same origin=] with |origin|,
return `false`.
7. Return `true`.
</ol>
### Credential Type Registry ### {#sctn-cred-type-registry}
This registry maps [=credential type registry/credential types=] (i.e., {{Credential/[[type]]}} values) to various values associated with a given credential type. For example: the [=credential type registry/Options Member Identifier=]
(formally, a [=dictionary member=] [=identifier=]) used in
{{CredentialCreationOptions}} and {{CredentialRequestOptions}} (i.e., "options dictionaries")
by their specifications.
Note: This registry is used by the [=relevant credential interface objects=] algorithm.
<table class="data">
<thead>
<tr>
<th><dfn for="credential type registry">Credential Type</dfn><br>
<small>(in alphabetical order)</small></th>
<th><dfn for="credential type registry">Options Member Identifier</dfn></th>
<th><dfn for="credential type registry">Appropriate Interface Object</dfn></th>
<th><dfn for="credential type registry">Get Permissions Policy</dfn></th>
<th><dfn for="credential type registry">Create Permissions Policy</dfn></th>
<th>Specification</th>
<th>Requestor Contact</th>
</tr>
</thead>
<tr>
<td>digital-credential</td>
<td>digital</td>
<td>{{DigitalCredential}}</td>
<td>digital-credentials-get</td>
<td>null</td>
<td>[[DIGITAL-CREDENTIALS]]</td>
<td><a href="https://wicg.io/">WICG</a></td>
</tr>
<tr>
<td>federated</td>
<td>federated</td>
<td>{{FederatedCredential}}</td>
<td>null</td>
<td>null</td>
<td>This specification: [[#federated]]</td>
<td><a href="https://www.w3.org/2011/webappsec/">W3C</a></td>
</tr>
<tr>
<td>identity</td>
<td>identity</td>
<td>{{IdentityCredential}}</td>
<td>[=identity-credentials-get=]</td>
<td>null</td>
<td>[[FEDCM]]</td>
<td><a href="https://www.w3.org/community/fed-id/">W3C</a></td>
</tr>
<tr>
<td>otp</td>
<td>otp</td>
<td>{{OTPCredential}}</td>
<td>[=otp-credentials-feature|otp-credentials=]</td>
<td>null</td>
<td>[[WEB-OTP]]</td>
<td><a href="https://wicg.io/">WICG</a></td>
</tr>
<tr>
<td>password</td>
<td>password</td>
<td>{{PasswordCredential}}</td>
<td>null</td>
<td>null</td>
<td>This specification: [[#passwords]]</td>
<td><a href="https://www.w3.org/2011/webappsec/">W3C</a></td>
</tr>
<tr>
<td>public-key</td>
<td>publicKey</td>
<td>{{PublicKeyCredential}}</td>
<td>[=publickey-credentials-get-feature|publickey-credentials-get=]</td>
<td>[=publickey-credentials-create-feature|publickey-credentials-create=]</td>
<td>[[WEBAUTHN]]</td>
<td><a href="https://www.w3.org/blog/webauthn/">W3C</a></td>
</tr>
</table>
<!-- NOTE: The below Registration Entry Requirements and Update Process is based on
https://www.w3.org/TR/timing-entrytypes-registry/, and is similar to other W3C
"registry" specs. I.e., this Requirements and Update Process is typical for
W3C registries. -->
#### Registration Entry Requirements and Update Process #### {#sctn-registry-requirements}
* Each [=credential type registry/credential type=] must be unique amongst the set of [=credential type registry/credential types=].
* Each registry entry must state the [=dictionary member=] [=identifier=] (known as the [=credential type registry/Options Member Identifier=] in the registry) used in the
credential specification's extentions of {{CredentialCreationOptions}} and
{{CredentialRequestOptions}}.
* Each registry entry must state the [=credential type registry/Appropriate Interface Object=] [=identifier=] for the
[=credential type registry/credential type=].
* Each registry entry must state the [=credential type registry/Get Permissions Policy=] [=permission=]
used when executing <a abstract-op>Request a `Credential`</a> for a
[=credential type registry/credential type=], or null if no [=Document/permissions policy=] is specified.
* Each registry entry must state the [=credential type registry/Create Permissions Policy=] [=permission=]
used when executing <a abstract-op>Create a `Credential`</a> for a
[=credential type registry/credential type=], or null if no [=Document/permissions policy=] is specified.
* Each registry entry must include a link that references a publicly available specification
defining the [=credential type registry/credential type=] and the [=dictionary member=] [=identifier=].
* Each registry entry's specification must include the requestor's contact information.
An update to this registry is an addition, change or deletion of a [=credential type registry/credential type=]'s registry entry.
Any person can request an update to this registry by pull requests to the
<a href="https://github.com/w3c/webappsec-credential-management">webappsec-credential-management</a>
repository.
The Web Applications Security Working Group will place it on an upcoming meeting agenda
and notify the requestor.
Consideration and disposition of the request is by consensus of the W3C Web Applications
Security Working Group.
The Chair will then notify the requestor of the outcome and update the registry accordingly.
## The `Credential` Interface ## {#the-credential-interface}
<pre class="idl">
[Exposed=Window, SecureContext]
interface Credential {
readonly attribute USVString id;
readonly attribute DOMString type;
static Promise<boolean> isConditionalMediationAvailable();
static Promise<undefined> willRequestConditionalCreation();
};
</pre>
<div dfn-for="Credential">
: <dfn attribute>id</dfn>
:: The credential's identifier. The requirements for the identifier are distinct for each type
of [=credential=]. It might represent a username for username/password tuples, for example.
: <dfn attribute>type</dfn>
:: This attribute's getter returns the value of the object's [=interface object=]'s
{{[[type]]}} slot, which specifies the [=credential/credential type=] represented by this object.
: <dfn method>isConditionalMediationAvailable()</dfn>
:: Returns a {{Promise}} that [=resolves=] with `true` if and only if the user agent supports the
{{CredentialMediationRequirement/conditional}} approach to
[[#mediation-requirements|mediation of credential requests]] for the [=credential/credential type=],
`false` otherwise.
{{Credential}}'s default implementation of {{Credential/isConditionalMediationAvailable()}}:
<ol class="algorithm">
1. Return [=a promise resolved with=] with `false`.
</ol>
The specification for any [=credential/credential type=] supporting
{{CredentialMediationRequirement/conditional}} mediation must explicitly override this
function to [=resolve=] to `true`.
Note: If this function is not present, {{CredentialMediationRequirement/conditional}}
mediation is not supported for the [=credential/credential type=].
: <dfn method>willRequestConditionalCreation()</dfn>
:: Returns a {{Promise}} that [=resolves=] after the user agent registers the relying party's intention
to create a credential using the {{CredentialMediationRequirement/conditional}} approach to
[[#mediation-requirements|mediation of credential creation]] for the [=credential/credential type=].
{{Credential}}'s default implementation of {{Credential/willRequestConditionalCreation()}}:
<ol class="algorithm">
1. Return [=a promise resolved with=] `undefined`.
</ol>
Note: If this method is not present, {{CredentialMediationRequirement/conditional}}
mediation for credential creation is not supported for the [=credential/credential type=].
: <dfn attribute>\[[type]]</dfn>
:: The {{Credential}} [=interface object=] has an internal slot named `[[type]]`, which
unsurprisingly contains a <dfn for="credential" lt="credential type">string representing the credential type</dfn>. The slot's value
is the empty string unless otherwise specified. See [[#sctn-cred-type-registry]] for a list of [=credential type registry/credential types=].
Note: The {{[[type]]}} slot's value will be the same for all credentials implementing a
particular interface, which means that developers can rely on `obj.type` returning a string
that unambiguously represents the specific kind of {{Credential}} they're dealing with.
: <dfn attribute>\[[discovery]]</dfn>
:: The {{Credential}} [=interface object=] has an internal slot named `[[discovery]]`,
representing the mechanism by which the user agent can collect credentials of
a given type. Its value is either
"<dfn enum-value for="Credential/[[discovery]]">`credential store`</dfn>" or
"<dfn enum-value for="Credential/[[discovery]]">`remote`</dfn>". The former value means that
all available credential information is stored in the user agent's [=credential store=],
while the latter means that the user agent can discover credentials outside of those
explicitly represented in the [=credential store=] via interaction with some external device
or service.
</div>
ISSUE: Talk to Tobie/Dominic about the [=interface object=] bits, here and in
[[#algorithm-request]], etc. I'm not sure I've gotten the terminology right. [=interface prototype
object=], maybe?
Some {{Credential}} objects are <dfn for="Credential" export>origin bound</dfn>: these contain an
internal slot named <dfn for="Credential" attribute>\[[origin]]</dfn>, which stores the [=origin=]
for which the {{Credential}} may be [=effective=].
### `Credential` Internal Methods ### {#credential-internal-methods}
The {{Credential}} [=interface object=] features several [=internal methods=] facilitating
retrieval and storage of {{Credential}} objects, with default "no-op" implementations
as specified in this section, below.
Unless otherwise specified, each [=interface object=] created for interfaces which [=interface/inherit=]
from {{Credential}} MUST provide implementations for at least one of these internal methods, overriding
{{Credential}}'s default implementations, as appropriate for the [=credential=] type. E.g.,
[[#passwordcredential-interface]], [[#federatedcredential-interface]], and [[WEBAUTHN]].
<h5 id="algorithm-collect-creds" algorithm>`[[CollectFromCredentialStore]]` internal method</h5>
<dfn for="Credential" method export>\[[CollectFromCredentialStore]](origin, options, sameOriginWithAncestors)</dfn>
is called with an [=environment settings object/origin=], a {{CredentialRequestOptions}}, and a boolean which
is true if and only if the caller's [=environment settings object=] is [=same-origin with its ancestors=].
The algorithm returns a set of {{Credential}} objects from the user agent's [=credential store=] that
match the options provided. If no matching {{Credential}} objects are available, the
returned set will be empty.
{{Credential}}'s default implementation of
{{Credential/[[CollectFromCredentialStore]](origin, options, sameOriginWithAncestors)}}:
<ol class="algorithm">
1. Return an empty set.
</ol>
<h5 id="algorithm-discover-creds" algorithm>`[[DiscoverFromExternalSource]]` internal method</h5>
<dfn for="Credential" method export>\[[DiscoverFromExternalSource]](origin, options, sameOriginWithAncestors)</dfn>
is called [=in parallel=] with an [=environment settings object/origin=], a {{CredentialRequestOptions}} object,
and a boolean which is true if and only if the caller's [=environment settings object=] is
[=same-origin with its ancestors=].
It returns a {{Credential}} if one can be
returned given the options provided, `null` if no credential is available, or throws an
error if discovery fails (for example, incorrect options could produce a {{TypeError}}).
If this kind of {{Credential}} is only [=effective=] for a single use or a limited time,
this method is responsible for generating new [=credentials=] using a [=credential source=].
{{Credential}}'s default implementation of
{{Credential/[[DiscoverFromExternalSource]](origin, options, sameOriginWithAncestors)}}:
<ol class="algorithm">
1. Return `null`.
</ol>
<h5 id="algorithm-store-cred" algorithm>`[[Store]]` internal method</h5>
<dfn for="Credential" method export>\[[Store]](credential, sameOriginWithAncestors)</dfn>
is called [=in parallel=] with a {{Credential}}, and a boolean which is true if and only if the caller's
[=environment settings object=] is [=same-origin with its ancestors=].
The algorithm returns once {{Credential}} is persisted to the [=credential store=].
{{Credential}}'s default implementation of {{Credential/[[Store]](credential, sameOriginWithAncestors)}}:
<ol class="algorithm">
1. Throw a `NotSupportedError`.
</ol>
<h5 id="algorithm-create-cred" algorithm>`[[Create]]` internal method</h5>
<dfn for="Credential" method export>\[[Create]](origin, options, sameOriginWithAncestors)</dfn>
is called [=in parallel=] with an [=environment settings object/origin=], a {{CredentialCreationOptions}},
and a boolean which is true if and only if the caller's
[=environment settings object=] is [=same-origin with its ancestors=].
The algorithm either:
* creates a {{Credential}}, or
* does not create a credential and returns `null`, or
* throws an error if creation fails due to exceptional situations
(for example, incorrect options could produce a {{TypeError}}).
When creating a {{Credential}}, it will return an algorithm that takes a [=global object=]
and returns an [=interface object=]
inheriting from {{Credential}}. This algorithm MUST be invoked from a [=task=].
Note: This algorithm's steps are defined on a per-[=credential/credential type=] basis.
{{Credential}}'s default implementation of {{Credential/[[Create]](origin, options, sameOriginWithAncestors)}}:
<ol class="algorithm">
1. Return `null`.
</ol>
### `CredentialUserData` Mixin ### {#credentialuserdata-mixin}
Some {{Credential}} objects contain data which aims to give users a human-readable disambiguation
mechanism in the [=credential chooser=] by providing a friendly name and icon:
<pre class="idl">
[SecureContext]
interface mixin CredentialUserData {
readonly attribute USVString name;
readonly attribute USVString iconURL;
};
</pre>
<div dfn-for="CredentialUserData">
: <dfn attribute>name</dfn>
:: A name associated with the credential, intended as a human-understandable public name for
display in a [=credential chooser=].
: <dfn attribute>iconURL</dfn>
:: A URL pointing to an image for the credential, intended for display in a
[=credential chooser=]. This URL MUST be an [=potentially trustworthy URL=].
</div>
## `navigator.credentials` ## {#framework-credential-management}
Developers retrieve {{Credential}}s and interact with the user agent's [=credential store=] via
methods exposed on the
{{CredentialsContainer}} interface, which hangs off the {{Navigator}} object as
<a attribute for="Navigator" lt="credentials">`navigator.credentials`</a>.
<pre class="idl">
partial interface Navigator {
[SecureContext, SameObject] readonly attribute CredentialsContainer credentials;
};
</pre>
The <dfn for="Navigator" attribute>`credentials`</dfn> attribute MUST return the
{{CredentialsContainer}} associated with the [=active document=]'s [=document/browsing context=].
Note: As discussed in [[#insecure-sites]], the credential management API is exposed only in
[=Secure Contexts=].
<pre class="idl">
[Exposed=Window, SecureContext]
interface CredentialsContainer {
Promise<Credential?> get(optional CredentialRequestOptions options = {});
Promise<undefined> store(Credential credential);
Promise<Credential?> create(optional CredentialCreationOptions options = {});
Promise<undefined> preventSilentAccess();
};
dictionary CredentialData {
required USVString id;
};
</pre>
<div dfn-for="CredentialsContainer">
: <dfn method>get(options)</dfn>
:: When {{CredentialsContainer/get()}} is called, the user agent MUST return the result of
executing <a abstract-op>Request a `Credential`</a> on
{{CredentialsContainer/get(options)/options}}.
<pre class="argumentdef" for="CredentialsContainer/get(options)">
options: The set of properties governing the scope of the request.
</pre>
: <dfn method lt="store(credential)|store()">store(credential)</dfn>
:: When {{CredentialsContainer/store()}} is called, the user agent MUST return the result of
executing <a abstract-op>Store a `Credential`</a> on
{{CredentialsContainer/store(credential)/credential}}.
<pre class="argumentdef" for="CredentialsContainer/store(credential)">
credential: The credential to be stored.
</pre>
: <dfn method lt="create(options)|create()">create(options)</dfn>
:: When {{CredentialsContainer/create()}} is called, the user agent MUST return the result of
executing <a abstract-op>Create a `Credential`</a> on
{{CredentialsContainer/create(options)/options}}.
<pre class="argumentdef" for="CredentialsContainer/create(options)">
options: The options used to create a `Credential`.
</pre>
: <dfn method>preventSilentAccess()</dfn>
:: When {{CredentialsContainer/preventSilentAccess()}} is called, the user agent MUST return
the result of executing <a abstract-op>Prevent Silent Access</a> on the [=current settings
object=].
Note: The intent here is a signal from the origin that the user has signed out. That
is, after a click on a "Sign out" button, the site updates the user's session info, and
calls `navigator.credentials.preventSilentAccess()`. This sets the [=origin/prevent silent
access flag=], meaning that credentials will not be automagically handed back to the
page next time the user visits.
Note: This function was previously called `requireUserMediation()` which should be considered
deprecated.
</div>
<div algorithm="create credentialscontainer">
When a {{Navigator}} object (|navigator|) is created, the user agent MUST create a
new {{CredentialsContainer}} object, using |navigator|'s [=relevant Realm=], and associate it
with |navigator|.
</div>
### The `CredentialRequestOptions` Dictionary ### {#credentialrequestoptions-dictionary}
In order to retrieve a {{Credential}} via {{CredentialsContainer/get()}}, the caller specifies a
few parameters in a {{CredentialRequestOptions}} object.
Note: The {{CredentialRequestOptions}} dictionary is an extension point. If and when new types of
credentials are introduced that require options, their dictionary types will be added to the
dictionary so they can be passed into the request. See [[#implementation-extension]].
<pre class="idl">
dictionary CredentialRequestOptions {
CredentialMediationRequirement mediation = "optional";
AbortSignal signal;
};
</pre>
<div dfn-for="CredentialRequestOptions" dfn-type="dict-member">
: <dfn>mediation</dfn>
:: This property specifies the mediation requirements for a given credential request. The
meaning of each enum value is described below in {{CredentialMediationRequirement}}.
Processing details are defined in [[#algorithm-request]].
: <dfn>signal</dfn>
:: This property lets the developer abort an ongoing {{CredentialsContainer/get()}} operation.
An aborted operation may complete normally (generally if the abort was received after the
operation finished) or reject with an [=AbortSignal/abort reason=].
</div>
<div class="note">
Earlier versions of this specification defined a boolean `unmediated` member. Setting that
to `true` had the effect of setting {{CredentialRequestOptions/mediation}} to
"{{CredentialMediationRequirement/silent}}", and setting it to `false` had the effect of
setting {{CredentialRequestOptions/mediation}} to "{{CredentialMediationRequirement/optional}}".
`unmediated` should be considered deprecated; new code should instead rely on
{{CredentialRequestOptions/mediation}}.
</div>
<div algorithm="relevant credential interfaces">
The <dfn for="CredentialRequestOptions,CredentialCreationOptions">relevant credential interface objects</dfn> for a given
{{CredentialCreationOptions}} or {{CredentialRequestOptions}} (|options|) is a set of [=interface objects=], collected as follows:
Note: This algorithm uses the [[#sctn-cred-type-registry|Credential Type Registry]].
<ol class="algorithm">
1. Let |settings| be the [=current settings object=].
1. Let |relevant interface objects| be an [=set/empty=] [=set=].
1. [=map/For each=] |optionKey| → <var ignore>optionValue</var> of |options|:
1. Let |credentialInterfaceObject| be the [=credential type registry/Appropriate Interface Object=]
(on |settings|' [=environment settings object/global object=]) whose [=credential
type registry/Options Member Identifier=] is |optionKey|.
1. Assert: |credentialInterfaceObject|'s {{[[type]]}} slot equals the [=credential type
registry/Credential Type=] whose [=credential type registry/Options Member
Identifier=] is |optionKey|.
1. Append |credentialInterfaceObject| to |relevant interface objects|.
1. Return |relevant interface objects|.
</ol>
</div>
<div algorithm="can collect locally">
A given {{CredentialRequestOptions}} (|options|) is
<dfn for="CredentialRequestOptions">matchable <i lang="la">a priori</i></dfn> if the following
steps return `true`:
<ol class="algorithm">
1. For each |interface| in |options|' [=relevant credential interface objects=]:
1. If |interface|'s {{Credential/[[discovery]]}} slot's value is not
"{{Credential/[[discovery]]/credential store}}", return `false`.
1. Return `true`.
</ol>
Note: When executing {{get(options)}}, we only return credentials without [=user mediation=] if
the provided {{CredentialRequestOptions}} is <a>matchable <i lang="la">a priori</i></a>. If any
credential types are requested that could require discovery from some external service (OAuth
tokens, security key authenticators, etc.), then [=user mediation=] will be required in order
to guide the discovery process (by choosing a federated identity provider, BTLE device, etc).
</div>
### Mediation Requirements ### {#mediation-requirements}
When making a request via {{get(options)}} or {{create(options)}}, developers can set a case-by-case requirement for
[=user mediation=] by choosing the appropriate {{CredentialMediationRequirement}} enum value.
Note: The [[#user-mediation]] section gives more detail on the concept in general, and its
implications on how the user agent deals with individual requests for a given origin).
<pre class="idl">
enum CredentialMediationRequirement {
"silent",
"optional",
"conditional",
"required"
};
</pre>
<div dfn-for="CredentialMediationRequirement" dfn-type="enum-value">
: <dfn>silent</dfn>
:: User mediation is suppressed for the given operation. If the operation can be performed
without user involvement, wonderful. If user involvement is necessary, then the operation
will return `null` rather than involving the user.
Note: The intended usage is to support ["Keep me signed-into this site"
scenarios](#example-mediation-silent), where a developer may wish to silently obtain
credentials if a user should be automatically signed in, but to delay bothering the user
with a sign-in prompt until they actively choose to sign-in.
: <dfn>optional</dfn>
:: If credentials can be handed over for a given operation without user mediation, they will
be. If [=requires user mediation|user mediation is required=], then the user agent will
involve the user in the decision.
Note: This is the default behavior for {{get()}}, and is intended to serve a case where a
developer has reasonable confidence that a user expects to start a sign-in operation. If
a user has just clicked "sign-in" for example, then they won't be surprised or confused to
see a [=credential chooser=] if necessary.
: <dfn>conditional</dfn>
:: For {{CredentialsContainer/get()}}, discovered credentials are presented to the user in a non-modal dialog along with an
indication of the [=origin=] which is requesting credentials. If the user makes a gesture
outside of the dialog, the dialog closes without resolving or rejecting the {{Promise}}
returned by the {{CredentialsContainer/get()}} method and without causing a user-visible
error condition. If the user makes a gesture that selects a credential, that credential is
returned to the caller. The [=origin/prevent silent access flag=] is treated as being `true`
regardless of its actual value: the {{CredentialMediationRequirement/conditional}} behavior
always involves [=user mediation=] of some sort if applicable credentials are discovered.
If no credentials are discovered, the user agent MAY prompt the user to take action in a way
that depends on the type of credential (e.g. to insert a device containing credentials).
Either way, the `get()` method MUST NOT resolve immediately with `null` to avoid revealing
the lack of applicable credentials to the website.
Websites can only pass {{CredentialMediationRequirement/conditional}} into the
{{CredentialsContainer/get()}} method if all of the [=relevant credential interface objects|credential
interfaces it refers to=] have overridden {{Credential/isConditionalMediationAvailable()}} to return
a {{Promise}} that [=resolves=] with `true`.
For {{CredentialsContainer/create()}}, if a user has previously consented to credential creation and
the user agent knows it recently mediated an authentication, then the `create()` call may resolve without
additional prominent modal interaction. If the user agent did not recently mediate an authentication or
does not have consent for credential creation, then the call must throw a "{{NotAllowedError}}" {{DOMException}}.
: <dfn>required</dfn>
:: The user agent will not hand over credentials without [=user mediation=], even if the
[=origin/prevent silent access flag=] is unset for an origin.
Note: This requirement is intended to support [reauthentication](#example-mediation-require)
or [user-switching](#example-mediation-switch) scenarios. Further, the requirement is tied
to a specific operation, and does not affect the [=origin/prevent silent access flag=] for the
origin. To set that flag, developers should call {{preventSilentAccess()}}.
</div>
#### Examples #### {#mediation-examples}
<div class="example" id="example-mediation-silent">
MegaCorp, Inc. wishes to seamlessly sign in users when possible. They can do so by calling
{{get()}} for all non-signed in users at some convinient point while a landing page is loading,
passing in a {{CredentialRequestOptions/mediation}} member set to
"{{CredentialMediationRequirement/silent}}". This ensures that users who have opted-into
dropping the requirements for user mediation (as described in [[#user-mediation-requirement]])
are signed in, and users who haven't opted-into such behavior won't be bothered with a confusing
[=credential chooser=] popping up without context:
<pre>
window.addEventListener('load', async () => {
const credentials = await navigator.<a for="Navigator" attribute>credentials</a>.<a for="CredentialsContainer" method lt="get()">get</a>({
...,
<a for="CredentialRequestOptions" dict-member>mediation</a>: '<a for="CredentialMediationRequirement" enum-value>silent</a>'
});
if (credentials) {
// Hooray! Let's sign the user in using these credentials!
}
});
</pre>
</div>
<div class="example" id="example-mediation-optional">
When a user clicks "Sign In", MegaCorp, Inc. wishes to give them the smoothest possible
experience. If they have [[#user-mediation-requirement|opted-into]] signing in without
[=user mediation=], and the user agent can unambigiously choose a credential, great! If
not, a [=credential chooser=] will be presented.
<pre>
document.querySelector('#sign-in').addEventListener('click', async () => {
const credentials = await navigator.<a for="Navigator" attribute>credentials</a>.<a for="CredentialsContainer" method lt="get()">get</a>({
...,
<a for="CredentialRequestOptions" dict-member>mediation</a>: '<a for="CredentialMediationRequirement" enum-value>optional</a>'
});
if (credentials) {
// Hooray! Let's sign the user in using these credentials!
}
});
</pre>
Note: MegaCorp, Inc. could also have left off the {{CredentialRequestOptions/mediation}}
member entirely, as "{{CredentialMediationRequirement/optional}}" is its default.
</div>
<div class="example" id="example-mediation-require">
MegaCorp, Inc. wishes to protect a sensitive operation by requiring a user to reauthenticate
before taking action. Even if a user has [[#user-mediation-requirement|opted-into]] signing in
without [=user mediation=], MegaCorp, Inc. can ensure that the user agent requires mediation
by calling {{get()}} with a {{CredentialRequestOptions/mediation}} member set to
"{{CredentialMediationRequirement/required}}":
Note: Depending on the security model of the browser or the credential type, this may require
the user to authenticate themselves in some way, perhaps by entering a master password, scanning
a fingerprint, etc. before a credential is handed to the website.
<pre>
document.querySelector('#important-form').addEventListener('submit', async () => {
const credentials = await navigator.<a for="Navigator" attribute>credentials</a>.<a for="CredentialsContainer" method lt="get()">get</a>({
...,
<a for="CredentialRequestOptions" dict-member>mediation</a>: '<a for="CredentialMediationRequirement" enum-value>required</a>'
});
if (credentials) {
// Verify that |credentials| enables access, and cancel the submission
// if it doesn't.
} else {
e.preventDefault();
}
});
</pre>
</div>
<div class="example" id="example-mediation-switch">
MegaCorp, Inc. wishes to support signing into multiple user accounts at once. In order to ensure
that the user gets a chance to select a different credential, MegaCorp, Inc. can call {{get()}}
with a {{CredentialRequestOptions/mediation}} member set to
"{{CredentialMediationRequirement/required}}" in order to ensure that that credentials aren't
returned automatically in response to clicking on an "Add account" button:
<pre>
document.querySelector('#switch-button').addEventListener('click', e => {
var c = await navigator.<a for="Navigator" attribute>credentials</a>.<a for="CredentialsContainer" method lt="get()">get</a>({
...,
<a for="CredentialRequestOptions" dict-member>mediation</a>: '<a for="CredentialMediationRequirement" enum-value>required</a>'
});
if (c) {
// Sign the user in using |c|.
}
});
</pre>
</div>
## The `CredentialCreationOptions` Dictionary ## {#credentialcreationoptions-dictionary}
In order to create a {{Credential}} via {{CredentialsContainer/create()}}, the caller specifies a
few parameters in a {{CredentialCreationOptions}} object.
Note: The {{CredentialCreationOptions}} dictionary is an extension point. If and when new types of
credentials are introduced, they will add to the dictionary so they can be passed into the
creation method. See [[#implementation-extension]], and the extensions introduced in this document:
[[#passwordcredential-interface]] and [[#federatedcredential-interface]].
<pre class="idl">
dictionary CredentialCreationOptions {
CredentialMediationRequirement mediation = "optional";
AbortSignal signal;
};
</pre>
<div dfn-for="CredentialCreationOptions" dfn-type="dict-member">
: <dfn>signal</dfn>
:: This property lets the developer abort an ongoing {{CredentialsContainer/create()}}
operation. An aborted operation may complete normally (generally if the abort was received
after the operation finished) or reject with an [=AbortSignal/abort reason=].
</div>
## Algorithms ## {#algorithms}
<h4 id="algorithm-request" algorithm>Request a `Credential`</h4>
The <dfn abstract-op>Request a `Credential`</dfn> algorithm accepts a {{CredentialRequestOptions}}
(|options|), and returns a {{Promise}} that resolves with a {{Credential}} if one can be
unambigiously obtained, or with `null` if not.
<ol class="algorithm">
1. Let |settings| be the [=current settings object=].
1. Assert: |settings| is a [=secure context=].
1. Let |document| be |settings|'s [=relevant global object=]'s [=associated Document=].
1. If |document| is not [=Document/fully active=], then return [=a promise rejected with=]
an "{{InvalidStateError}}" {{DOMException}}.
1. If <code>|options|.{{CredentialRequestOptions/signal}}</code> is [=AbortSignal/aborted=],
then return [=a promise rejected with=]
<code>|options|.{{CredentialRequestOptions/signal}}</code>'s [=AbortSignal/abort reason=].
1. Let |interfaces| be |options|'s [=relevant credential interface objects=].
1. If |interfaces| is [=set/empty=], then return[=a promise rejected with=]
a "{{NotSupportedError}}" {{DOMException}}.
1. [=set/For each=] |interface| of |interfaces|:
1. If |options|.{{CredentialRequestOptions/mediation}} is
{{CredentialMediationRequirement/conditional}} and |interface| does
not support {{CredentialMediationRequirement/conditional}}
[=user mediation=], return [=a promise rejected with=]
a "{{TypeError}}" {{DOMException}}.
1. If |settings|' [=active credential types=] [=set/contains=] |interface|'s
{{Credential/[[type]]}}, return [=a promise rejected with=] a "{{NotAllowedError}}"