PublicKeyCredentialCreationOptions - 表示用于创建 PublicKeyCredential 的选项
PublicKeyCredentialCreationOptions 是 Web 身份验证 API 的字典,包含传递给 navigators.credentials.create(),用于创建 PublicKeyCredential 的选项。
属性
 PublicKeyCredentialCreationOptions.rp
一个对象,描述请求凭证创建的依赖方。
 PublicKeyCredentialCreationOptions.user
一个对象,描述为其生成凭据的用户帐户。
 PublicKeyCredentialCreationOptions.challenge
一个 BufferSource,由依赖方的服务器发出,用作加密挑战。该值将由身份验证者签名,并且签名将作为 AuthenticatorAttestationResponse.attestationObject 的一部分发送回去。
 PublicKeyCredentialCreationOptions.pubKeyCredParams
一个 Array,用于指定凭据的所需功能,包括其类型和用于密码签名操作的算法。该数组按优先级从高到低排序。
 PublicKeyCredentialCreationOptions.timeout 可选
一个数字提示(以毫秒为单位),指示调用者愿意等待创建操作完成的时间。该提示可能会被浏览器覆盖。
 PublicKeyCredentialCreationOptions.excludeCredentials 可选
一个 Array,表示现有凭证的描述符。它是由依赖方提供的,以避免为已经拥有一些现有用户的新用户创建新的公共密钥凭据。
 PublicKeyCredentialCreationOptions.authenticatorSelection 可选
一个对象,其属性是用于过滤掉创建操作的潜在身份验证者的条件。
 PublicKeyCredentialCreationOptions.attestation 可选
一个 String,指示应如何传输证明(对于认证者的来源)。
 PublicKeyCredentialCreationOptions.extensions 可选
一个对象,表示多个客户端扩展输入。这些扩展用于请求其他处理(例如,处理旧式 FIDO API 凭据,在身份验证器上提示特定文本等)。
方法
无。
实例
// COSE 算法的一些实例
const cose_alg_ECDSA_w_SHA256 = -7;
const cose_alg_ECDSA_w_SHA512 = -36;
var createCredentialOptions = {
    // 新凭证的格式为 publicKey
    publicKey: {
        // 依赖方(Relying Party)
        rp: {
            name: "示例公司",
            id: "login.example.com",
            icon: "https://login.example.com/login.ico"
        },
        // 来自服务器的加密挑战
        challenge: new Uint8Array(26), 
        // 用户
        user: {
            id: new Uint8Array(16),
            name: "john.p.smith@example.com",
            displayName: "John P. Smith",
        },
        // 要求新密钥对的格式
        pubKeyCredParams: [{
            type: "public-key",
            alg: cose_alg_ECDSA_w_SHA256,
        }],
        // 1 分钟后超时
        timeout: 60000,
        // 不要发送身份验证者的源证明
        attestation: "none",
        extensions: {
          uvm: true,
          exts: true
        },
        // 筛选出绑定到设备的身份验证器
        authenticatorSelection:{
          authenticatorAttachment: "cross-platform",
          requireResidentKey: true,
          userVerification: "preferred"
        },
        // 排除用户的现有凭证
        excludeCredentials: [
          {
            type: "public-key",
            // john.doe@example.com 的 ID
            id  : new Uint8Array(26) /* 这实际上是由服务器给出的 */
          },
          {
            type: "public-key",
            // john-doe@example.com 的 ID
            id : new Uint8Array(26) /* 另一个 ID */
          }
        ]
    }
};
// 使用上面的选项创建新的凭证
navigator.credentials.create(createCredentialOptions)
  .then(function (newCredentialInfo) {
    var attestationResponse = newCredentialInfo.response;
    var clientExtensionsOutputs = newCredentialInfo.getClientExtensionsResults();
    // 将响应发送到依赖方服务器,它将验证内容并创建新的凭据
  }).catch(function (err) {
    // 正确处理任何错误
    console.error(err);
  });;
规范
| 规范 | 状态 | 备注 | 
|---|---|---|
| Web Authentication: An API for accessing Public Key Credentials Level 1 PublicKeyCredentialCreationOptions dictionary 的定义  | 
候选推荐 | 初始定义。 | 
桌面浏览器兼容性
| 特性 | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | 
|---|---|---|---|---|---|---|
| 基础支持 | 67 | 未知 | 60 | 未知 | 支持 | 未知 | 
attestation | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
authenticatorSelection | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
challenge | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
excludeCredentials | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
extensions | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
pubKeyCredParams | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
rp | 67 | 未知 | 60 | 未知 | 支持 | 未知 | 
timeout | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
user | 67 | 未知 | 60 | 未知 | 未知 | 未知 | 
移动浏览器兼容性
| 特性 | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari | 
|---|---|---|---|---|---|---|---|
| 基础支持 | 不支持 | 67 | 未知 | 未知 | 未知 | 支持 | 未知 | 
attestation | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
authenticatorSelection | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
challenge | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
excludeCredentials | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
extensions | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
pubKeyCredParams | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
rp | 不支持 | 67 | 未知 | 未知 | 未知 | 支持 | 未知 | 
timeout | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
user | 不支持 | 67 | 未知 | 未知 | 未知 | 未知 | 未知 | 
相关链接
PublicKeyRequestOptions:提供公钥检索操作选项的字典