Credential Management Level 1 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. User agents implementing that API prompt the user to select a way to handle a credential request, after which the user agent returns a credential to the originating site. This specification defines capabilities that enable third-party Web applications to handle credential requests and storage.
The Credentials Community Group maintains a list of all bug reports that the group has not yet addressed. This draft highlights some of the pending issues that are still to be discussed in the community group. No decision has been taken on the outcome of these issues including whether they are valid. Pull requests with proposed specification text for outstanding issues are strongly encouraged.
The mission of the Credentials Community Group is to explore the creation, storage, presentation, verification, and user control of credentials. Its focus is placed on a verifiable credential (a set of claims) created by an issuer about a subject: a person, group, or thing. It seeks solutions inclusive of approaches such as: self-sovereign identity; presentation of proofs by the bearer; data minimization; and centralized, federated, and decentralized registry and identity systems. Therefore, the Credentials Community Group presents a specification that extends the Credential Management Level 1 API to allow users to designate trusted third party Web applications as handlers for credential requests and credential storage.
A credential repository is a Web application that can handle credential requests and credential storage on behalf of the user. This specification defines a number of new Web platform features to handle credential requests and credential storage:
This specification does not address how software built with operating-system specific mechanisms (e.g., "native mobile apps") handle credential requests and credential storage.
This specification defines one class of products:
A user agent MUST behave as described in this specification to be considered conformant. In this specification, user agent means a Web browser or other interactive user agent as defined in [[!HTML5]].
User agents MAY implement algorithms given in this specification in any way desired, so long as the end result is indistinguishable from the result that would be obtained by the specification's algorithms.
A conforming Credential Handler API user agent MUST also be a conforming implementation of the IDL fragments of this specification, as described in the “Web IDL” specification. [[!WEBIDL-LS]]
In this document we envision the following flow for a credential request:
The origin information of the relying party may be blinded when received via a CredentialRequestEvent.
An origin may implement a credential repository with more than one service worker and therefore multiple credential handlers may be registered per origin. The handler that is invoked is determined by the selection made by the user of a credential hint. The service worker which stored the credential hint with its CredentialManager is the one that will be invoked.
The logic of a credential handler is driven by the WebCredential types that it supports. Some WebCredential types may require very little processing on the part of the credential handler other than retrieving a WebCredential from its storage and returning it as a response.
In contrast, some Web Credential types, such as VerifiableProfile include a custom query parameter that must be understood and processed by the credential handler in order for it to return an appropriate WebCredential in response. This may involve presenting a user interface to allow the user to make selections. In some cases, a credential handler may need to generate a WebCredential dynamically with the assistance of an issuer or blinding service. It may also need to generate a zero knowledge proof or use some other privacy enhancing cryptographic method.
Therefore, handling a credential request may include numerous interactions: with the user through a new contextual window or other APIs (such as [[!WebCryptoAPI]]) or with other services and origins through web requests or other means.
Once a WebCredential is returned to the relying party website, it is its job to perform whatever verification is appropriate for its type.
This specification does not address the activities that occur between the credential handler accepting the CredentialRequestEvent and the credential handler returning a response. All of the activities which may be required to configure the credential handler and handle the credential request are left to the implementation of the credential handler, including:
Thus, an origin will rely on many other Web technologies defined elsewhere for lifecycle management, security, user authentication, user interaction, and so on.
The logic of a credential handler is driven by the WebCredential types that it supports. Some WebCredential types may require very little processing on the part of the credential handler other than storing the WebCredential in a database and returning it as a response.
In contrast, some Web Credential types, such as VerifiableProfile may include multiple sub-credentials whereby the user may only elect to store some subset of them, through the use of a user interface provided by the credential handler.
Handling credential storage may include numerous interactions: with the user through a new contextual window or other APIs (such as [[!WebCryptoAPI]]) or with other services and origins through web requests or other means.
The WebCredential that is returned to the issuer website provides information on what was stored by the credential handler, enabling the issuer website to take whatever next actions are appropriate.
This specification does not address the activities that occur between the credential handler accepting the CredentialStoreEvent and the credential handler returning a response. All of the activities which may be required to configure the credential handler and handle credential storage are left to the implementation of the credential handler, including:
Thus, an origin will rely on many other Web technologies defined elsewhere for lifecycle management, security, user authentication, user interaction, and so on.
This specification does not address how third-party mobile credential repository apps interact (through proprietary mechanisms) with user agents, or how user agents themselves provide simple credential repository functionality.
ServiceWorkerRegistration
interface
This specification extends the ServiceWorkerRegistration interface with the addition of a credentialManager attribute.
partial interface ServiceWorkerRegistration { readonly attribute CredentialManager credentialManager; };
[SecureContext, Exposed=(Window,Worker)] interface CredentialManager { [SameObject] readonly attribute CredentialHints hints; [Exposed=Window] static Promise<PermissionState> requestPermission(); };
The CredentialManager is used by credential repositories to manage their associated hints and supported WebCredential types.
This attribute allows manipulation of credential hints associated with a service worker (and therefore its credential handler). To be a candidate credential handler, a handler must have at least one registered credential hint to present to the user. That instrument needs to match the WebCredential types and type-specific query information specified by the credential request.
The user agent is NOT REQUIRED to prompt the user to grant permission to the origin for each new supported WebCredential type or new credential hint.
When called, this method executes the following steps:
[SecureContext, Exposed=(Window,Worker)] interface CredentialHints { Promise<boolean> delete(DOMString hintKey); Promise<CredentialHint> get(DOMString hintKey); Promise<sequence<DOMString>> keys(); Promise<boolean> has(DOMString hintKey); Promise<void> set(DOMString hintKey, CredentialHint hint); Promise<void> clear(); };
The CredentialHints interface represents a collection of credential hints, each uniquely identified by a hintKey. The hintKey identifier will be passed to the credential handler to indicate the CredentialHint selected by the user. A CredentialHint is associated with a context or aspect of the user for which they store certain credentials, similar to a digital version of a physical wallet.
When called, this method executes the following steps:
When called, this method executes the following steps:
When called, this method executes the following steps:
When called, this method executes the following steps:
When called, this method executes the following steps:
When called, this method executes the following steps:
dictionary CredentialHint { required DOMString name; sequence<ImageObject> icons; sequence<DOMString> enabledTypes; object match; };
dictionary ImageObject { required USVString src; DOMString sizes; DOMString type; };
When this algorithm with inputImages parameter is invoked, the user agent must run the following steps:
According to the step 2.3, it is also possible to use the relative url for image.src. The following examples illustrate how relative URL resolution works in different execution contexts.
<-- In this example, code is located in https://www.example.com/wallet/index.html --> <script> const hintKey = "c8126178-3bba-4d09-8f00-0771bcfd3b11"; const { registration } = await navigator.serviceWorker.register("/register/sw.js"); await registration.credentialManager.credentialHints.set({ hintKey, { name: "My social account: pat@example.com", enabledTypes: ["VerifiableProfile"], icons: [{ src: "icon/lowres.webp", sizes: "48x48", type: "image/webp" }], match: { VerifiableProfile: { id: 'did:method1:1234-1234-1234-1234' } } }); const { storedHint } = await registration.credentialManager.credentialHints.get(hintKey); // storedHint.icons[0].src == "https://www.example.com/wallet/icon/lowres.webp"; </script>
// In this example, code is located in https://www.example.com/register/sw.js const hintKey = "c8126178-3bba-4d09-8f00-0771bcfd3b11"; await self.registration.credentialManager.credentialHints.set({ hintKey, { name: "My social account: pat@example.com", enabledTypes: ["VerifiableProfile"], icons: [{ src: "../wallet/icon/lowres.webp", sizes: "48x48", type: "image/webp" }], match: { VerifiableProfile: { id: 'did:method1:1234-1234-1234-1234' } } }); const { storedHint } = await registration.credentialManager.credentialHints.get(hintKey); // storedHint.icons[0].src == "https://www.example.com/wallet/icon/lowres.webp";
The following example shows how to register a credential handler:
button.addEventListener("click", async() => { if (!window.CredentialManager) { return; // not supported, so bail out. } const result = await CredentialManager.requestPermission(); if (result !== "granted") { return; } const { registration } = await navigator.serviceWorker.register('/sw.js'); // Excellent, we got it! Let's now set up the user's hints. await addInstruments(registration); }, { once: true }); function addHints(registration) { return Promise.all([ registration.credentialManager.hints.set( "dc2de27a-ca5e-4fbd-883e-b6ded6c69d4f", { name: "My social account: pat@example.com", enabledTypes: ["VerifiableProfile"], icons: [{ src: "icon/lowres.webp", sizes: "48x48", type: "image/webp" }], match: { VerifiableProfile: { id: 'did:method1:1234-1234-1234-1234' } } }), registration.credentialManager.hints.set( "c8126178-3bba-4d09-8f00-0771bcfd3b11", { name: "My business account: pat@business.example.com", enabledTypes: ["VerifiableProfile"], match: { VerifiableProfile: { id: 'did:method1:1234-1234-1234-1235' } } }), registration.credentialManager.hints.set( "new-hint", { name: "Add a new identity", enabledTypes: ["VerifiableProfile"] }), ]); };
TODO: define matching algorithm here
After applying the matching algorithm, the user agent displays the matching credential hints for the user to make a selection. This specification includes a limited number of display requirements; most user experience details are left to implementers.
The following are examples of credential hint ordering:
The user agent MUST enable the user to select any displayed hint.
Users agents may wish to enable the user to select individual displayed CredentialHints. The credential handler would receive information about the selected hint and could take action, potentially eliminating an extra click (first open the credential repository app then select the hint).
Only when a website invokes the get() and passes a WebCredentialRequestOptions or the store() method and passes a WebCredential, will CredentialHints be presented to the user for selection.
Once the user has selected a CredentialHint, the user agent fires a CredentialRequestEvent (or a CredentialStoreEvent if the Credential Management method called was store()) and uses the subsequent WebCredential as a response.
[SecureContext, Exposed=(Window,Worker)] interface WebCredential : Credential { readonly attribute USVString dataType; readonly attribute object data; };
This specification extends the ServiceWorkerGlobalScope interface.
partial interface ServiceWorkerGlobalScope { attribute EventHandler oncredentialrequest; attribute EventHandler oncredentialstore; };
The oncredentialrequest attribute is an event handler whose corresponding event handler event type is CredentialRequestEvent.
The oncredentialstore attribute is an event handler whose corresponding event handler event type is CredentialStoreEvent.
The CredentialRequestEvent represents the data and methods available to a Credential Handler after selection by the user. The user agent communicates the WebCredentialRequestOptions to the Credential Handler.
[Constructor(DOMString type, CredentialRequestEventInit eventInitDict), Exposed=ServiceWorker] interface CredentialRequestEvent : ExtendableEvent { readonly attribute USVString credentialRequestOrigin; readonly attribute object credentialRequestOptions; readonly attribute DOMString hintKey; Promise<WindowClient?> openWindow(USVString url); void respondWith(Promise<WebCredential>handlerResponsePromise); };
This attribute is a string that indicates the origin where the [[!credential-managment-1]] method get() was called.
The origin information of the relying party may be blinded when received via a CredentialRequestEvent. It would be blinded to allow it to still be signed without revealing where the request came from. The user agent would be responsible for indicating the origin of the request via its user interface.
This attribute contains WebCredentialRequestOptions dictionary containing the WebCredential type and type-specific query that describes the credentials requested by the web site.
This attribute indicates the CredentialHint selected by the user. It corresponds to the hintKey provided to the CredentialManager.hints interface during registration.
This method is used by the credential handler to show a window to the user. When called, it runs the open window algorithm.
This method is used by the credential handler to provide a WebCredential when the request has been fulfilled. When called, it runs the Respond to Credential Request Algorithm with event and handlerResponsePromise as arguments.
dictionary CredentialRequestEventInit : ExtendableEventInit { USVString credentialRequestOrigin; WebCredentialRequestOptions credentialRequestOptions; DOMString hintKey; };
The credentialRequestOrigin, credentialRequestOptions, and hintKey members share their definitions with those defined for CredentialRequestEvent.
Instances of CredentialRequestEvent are created with the internal slots in the following table:
Internal Slot | Default Value | Description (non-normative) |
---|---|---|
[[\windowClient]] | null | The currently active WindowClient. This is set if a credential handler is currently showing a window to the user. Otherwise, it is null. |
[[\fetchedImage]] | undefined | This value is a result of fetching image object or a fallback image provided by the user agent. |
[[\respondWithCalled]] | false | YAHO |
Upon receiving a credential request by way of get() and subsequent user selection of a credential hint, the user agent MUST run the following steps:
The CredentialStoreEvent represents the data and methods available to a Credential Handler after selection by the user. The user agent communicates the WebCredential to be stored to the Credential Handler.
[Constructor(DOMString type, CredentialStoreEventInit eventInitDict), Exposed=ServiceWorker] interface CredentialStoreEvent : ExtendableEvent { readonly attribute USVString credentialRequestOrigin; readonly attribute object credential; readonly attribute DOMString hintKey; Promise<WindowClient?> openWindow(USVString url); void respondWith(Promise<WebCredential>handlerResponsePromise); };
This attribute is a string that indicates the origin where the [[!credential-managment-1]] method store() was called.
This attribute contains WebCredential dictionary containing the specific credential information that the web site is requesting the user to store.
This attribute indicates the CredentialHint selected by the user. It corresponds to the hintKey provided to the CredentialManager.hints interface during registration.
This method is used by the credential handler to show a window to the user. When called, it runs the open window algorithm.
This method is used by the credential handler to provide a WebCredential when the storage request has been fulfilled. When called, it runs the Respond to Store Credential Algorithm with event and handlerResponsePromise as arguments.
dictionary CredentialStoreEventInit : ExtendableEventInit { USVString credentialRequestOrigin; WebCredential credential; DOMString hintKey; };
The credentialRequestOrigin, credential, and hintKey members share their definitions with those defined for CredentialStoreEvent.
Instances of CredentialStoreEvent are created with the internal slots in the following table:
Internal Slot | Default Value | Description (non-normative) |
---|---|---|
[[\windowClient]] | null | The currently active WindowClient. This is set if a credential handler is currently showing a window to the user. Otherwise, it is null. |
[[\fetchedImage]] | undefined | This value is a result of fetching image object or a fallback image provided by the user agent. |
[[\respondWithCalled]] | false | YAHO |
Upon receiving a credential storage request by way of store() and subsequent user selection of a credential hint, the user agent MUST run the following steps:
An invoked credential handler may or may not need to display information about itself or request user input. Some examples of potential credential handler display include:
A credential handler that requires visual display and user interaction, may call openWindow() to display a page to the user.
Since user agents know that this method is connected to the CredentialRequestEvent or a CredentialStoreEvent, they SHOULD render the window in a way that is consistent with the flow and not confusing to the user. The resulting window client is bound to the tab/window that initiated the request. A single credential handler SHOULD NOT be allowed to open more than one client window using this method.
This algorithm resembles the Open Window Algorithm in the Service Workers specification and mirrors the one provided in the Payment Handler API specification.
Should we refer to the Service Workers specification instead of copying their steps?
about:blank
, return a
Promise rejected with a TypeError.
This example shows how to write a service worker that listens to the CredentialRequestEvent and the CredentialStoreEvent. When a CredentialRequestEvent or CredentialStoreEvent is received, the service worker opens a window to interact with the user.
self.addEventListener('credentialrequest', function(e) { e.respondWith(new Promise(function(resolve, reject) { self.addEventListener('message', listener = function(e) { self.removeEventListener('message', listener); if (e.data.hasOwnProperty('name')) { reject(e.data); } else { resolve(e.data); } }); e.openWindow("https://www.example.com/wallet/get") .then(function(windowClient) { windowClient.postMessage(e.data); }) .catch(function(err) { reject(err); }); })); }); self.addEventListener('credentialstore', function(e) { e.respondWith(new Promise(function(resolve, reject) { self.addEventListener('message', listener = function(e) { self.removeEventListener('message', listener); if (e.data.hasOwnProperty('name')) { reject(e.data); } else { resolve(e.data); } }); e.openWindow("https://www.example.com/wallet/store") .then(function(windowClient) { windowClient.postMessage(e.data); }) .catch(function(err) { reject(err); }); })); });
Using the simple scheme described above, a trivial HTML page that is loaded into the credential handler window might include the following script:
<script> window.addEventListener("message", function(e) { var credentialRequestOptions = event.data.credentialRequestOptions; // TODO: process the query found in the request options and present // choices to the user // await ... e.source.postMessage({ type: 'response', credential: { dataType: 'VerifiableProfile', data: { '@context': 'https://w3id.org/credentials/v1', // ... signature: { ... } } } }); window.close(); }); </script>
dictionary CredentialHandlerResponse { DOMString dataType; object data; };
The WebCredential type for the credential that the user selected to fulfill the request.
A JSON-serializable object that provides a WebCredential type specific message used by the relying party to authenticate the user.
The user agent receives a successful response from the credential handler through resolution of the Promise provided to the respondWith() function of the corresponding CredentialRequestEvent interface. The application is expected to resolve the Promise with a CredentialHandlerResponse instance containing the response. In case of user cancellation or error, the application may signal failure by rejecting the Promise.
If the Promise is rejected, the user agent MUST run the credential repository failure algorithm. The exact details of this algorithm are left to implementers. Acceptable behaviors include, but are not limited to:
When this algorithm is invoked with event and handlerResponsePromise parameters, the user agent MUST run the following steps:
The following example shows how to respond to a credential request:
credentialRequestEvent.respondWith(new Promise(function(accept,reject) { /* ... processing may occur here ... */ accept({ dataType: "VerifiableProfile", data: { "@context": "https://w3id.org/credentials/v1", // ... } }); }));
This specification relies on several other underlying specifications.
TypeError
, and JSON.stringify
are
defined by [[!ECMA-262-2015]].
The term JSON-serialize applied to a given object means to run the algorithm specified by the original value of the JSON.stringify function on the supplied object, passing the supplied object as the sole argument, and return the resulting string. This can throw an exception.
When this specification says to throw an error, the user agent must throw an error as described in [[!WEBIDL]]. When this occurs in a sub-algorithm, this results in termination of execution of the sub-algorithm and all ancestor algorithms until one is reached that explicitly describes procedures for catching exceptions.
The algorithm for converting an ECMAScript value to a dictionary is defined by [[!WEBIDL]].
DOMException and the following DOMException types from [[!WEBIDL-LS]] are used:
InvalidAccessError
"
InvalidStateError
"
NotAllowedError
"
NotFoundError
"
OperationError
"
SecurityError
"
ServiceWorkerRegistration
,
ServiceWorkerGlobalScope
,
handle
functional event, extend lifetime
promises,pending promises
count, containing
service worker registration, uninstalling flag,
Try Clear
Registration, Try Activate, and
scope URL are
defined in [[!SERVICE-WORKERS]].
The authors would like to acknowledge the editors and authors of the Payment Request and Payment Handler specifications as this specification has been largely influenced by their design and language.
TODO