注册安全付款确认

如需在交易中使用安全付款确认 (SPC),客户必须先注册身份验证器。此流程与 WebAuthn 注册流程非常相似,只不过多了付款扩展程序。

本文介绍了作为依赖方 (RP) 的签发银行如何实现 SPC 注册。安全付款确认概览中进一步介绍了用户体验。

安全付款确认注册流程是怎样的?

SPC 是 WebAuthn 标准的扩展。

自 2022 年 4 月起,SPC 仅支持桌面设备上的用户验证平台身份验证器 (UVPA)。这意味着,客户需要使用内置身份验证器的桌面设备或笔记本电脑,例如:

  • 在 macOS 设备上使用解锁功能(包括触控 ID)
  • Windows 设备上的 Windows Hello

注册设备

信赖方 (RP) 注册设备时应遵循足够严格的用户验证流程。RP 必须确保客户已使用强效身份验证方法登录网站,以免账号被轻易盗用。请注意:在此过程中缺乏安全性也会使 SPC 面临风险。

RP 成功对客户进行身份验证后,客户现在可以注册设备了。

依赖方网站上的典型注册工作流

功能检测

在要求客户注册设备之前,RP 必须检查浏览器是否支持 SPC。

const isSecurePaymentConfirmationSupported = async () => {   if (!'PaymentRequest' in window) {     return [false, 'Payment Request API is not supported'];   }    try {     // The data below is the minimum required to create the request and     // check if a payment can be made.     const supportedInstruments = [       {         supportedMethods: "secure-payment-confirmation",         data: {           // RP's hostname as its ID           rpId: 'rp.example',           // A dummy credential ID           credentialIds: [new Uint8Array(1)],           // A dummy challenge           challenge: new Uint8Array(1),           instrument: {             // Non-empty display name string             displayName: ' ',             // Transparent-black pixel.             icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==',           },           // A dummy merchant origin           payeeOrigin: 'https://non-existent.example',         }       }     ];      const details = {       // Dummy shopping details       total: {label: 'Total', amount: {currency: 'USD', value: '0'}},     };      const request = new PaymentRequest(supportedInstruments, details);     const canMakePayment = await request.canMakePayment();     return [canMakePayment, canMakePayment ? '' : 'SPC is not available'];   } catch (error) {     console.error(error);     return [false, error.message];   } };  isSecurePaymentConfirmationSupported().then(result => {   const [isSecurePaymentConfirmationSupported, reason] = result;   if (isSecurePaymentConfirmationSupported) {     // Display the payment button that invokes SPC.   } else {     // Fallback to the legacy authentication method.   } }); 

注册身份验证器

如需为 SPC 注册设备,请按照 WebAuthn 注册流程进行操作,并满足以下要求:

  • 平台身份验证器是必需的:authenticatorSelection.authenticatorAttachmentplatform
  • 需要进行用户验证:authenticatorSelection.userVerificationrequired
  • 必须提供可检测到的凭据(常驻密钥):authenticatorSelection.residentKeyrequired

此外,使用 isPayment: true 指定“付款”扩展程序。如果指定此扩展程序但不满足上述要求,则会抛出异常

其他一些注意事项:

  • rp.id:RP 的主机名。域名的 eTLD+1 部分必须与其注册地相符。它可用于对与 eTLD+1 匹配的网域进行身份验证。
  • user.id:用户标识符的二进制表达式。成功完成身份验证后,系统会返回相同的标识符,因此 RP 应提供持卡人的一致用户标识符。
  • excludeCredentials:一组凭据,以便 RP 避免注册相同的身份验证器。

如需详细了解 WebAuthn 注册流程,请参阅 webauthn.guide

注册代码示例:

const options = {   challenge: new Uint8Array([21...]),   rp: {     id: "rp.example",     name: "Fancy Bank",   },   user: {     id: new Uint8Array([21...]),     name: "[email protected]",     displayName: "Jane Doe",   },   excludeCredentials: [{     id: new Uint8Array([21...]),     type: 'public-key',     transports: ['internal'],   }, ...],   pubKeyCredParams: [{     type: "public-key",     alg: -7 // "ES256"   }, {     type: "public-key",     alg: -257 // "RS256"   }],   authenticatorSelection: {     userVerification: "required",     residentKey: "required",     authenticatorAttachment: "platform",   },   timeout: 360000,  // 6 minutes    // Indicate that this is an SPC credential. This is currently required to   // allow credential creation in an iframe, and so that the browser knows this   // credential relates to SPC.   extensions: {     "payment": {       isPayment: true,     }   } };  try {   const credential = await navigator.credentials.create({ publicKey: options });   // Send new credential info to server for verification and registration. } catch (e) {   // No acceptable authenticator or user refused consent. Handle appropriately. } 

成功注册后,RP 会收到要发送到服务器进行验证的凭据。

验证注册

在服务器上,RP 必须验证凭据并保留公钥以供日后使用。服务器端注册流程与常规 WebAuthn 注册相同。无需执行任何其他操作即可遵守 SPC。

从 iframe 中进行注册

如果付款人尚未向 RP(付款发卡机构)注册其设备,则可以前往商家网站进行注册。在购买交易期间成功完成身份验证后,RP 可以请求付款人在 iframe 中间接注册其设备。

在付款期间在商家网站上注册的工作流程。

为此,商家或父级网站必须使用权限政策在 iframe 中明确允许此操作。发卡机构按照在 iframe 中注册身份验证器的相同步骤操作。

商家可以通过以下两种方式允许注册:

  1. 从商家网域提供的 HTML 中的 iframe 标记会添加 allow 属性:

    <iframe name="iframe" allow="payment https://spc-rp.glitch.me"></iframe> 

    确保 allow 属性包含 payment 和调用 WebAuthn 注册的 RP 源。

  2. 父级框架文档(从商家网域提供)会随 Permissions-Policy HTTP 标头一起发送:

    Permissions-Policy: payment=(self "https://spc-rp.glitch.me") 

后续步骤

设备向信赖方注册后,客户便可在商家的网站上使用安全付款确认功能确认付款。