简体   繁体   English

在跨域 iframe 中使用 `navigator.credentials.get()` 会出现错误“本文档中未启用‘publickey-credentials-get’功能”

[英]Using `navigator.credentials.get()` in cross-origin iframe gives error "'publickey-credentials-get' feature is not enabled in this document"

Getting the error while logging into an iframe through webauthn.通过 webauthn 登录 iframe 时出现错误。

The 'publickey-credentials-get' feature is not enabled in this document.本文档中未启用“publickey-credentials-get”功能。 Permissions Policy may be used to delegate Web Authentication capabilities to cross-origin child frames.权限策略可用于将 Web 身份验证功能委托给跨域子帧。

Here is the link to the example https://jsfiddle.net/14kj25nr/ .这是示例https://jsfiddle.net/14kj25nr/的链接。 I have registered a user "test_account" directly through webauthn.io and then tried to login into it through jsfiddle.我已经通过 webauthn.io 直接注册了一个用户“test_account”,然后尝试通过 jsfiddle 登录。 It says to use publickey-credentials-get , but I couldn't find a way to use it to get it to work.它说要使用publickey-credentials-get ,但我找不到一种方法来使用它来让它工作。 Any help would be appreciated.任何帮助,将不胜感激。

Update:更新:

I have added the allow attribute for the iframe allow="publickey-credentials-get" .我为 iframe allow="publickey-credentials-get"添加了允许属性。 It still gives me the same error.它仍然给我同样的错误。 The example in the fiddle is updated.小提琴中的示例已更新。

The Web Authentication API is disabled by default in cross-origin iframes. Web 身份验证 API 在跨域 iframe 中默认禁用。 To override this default policy and indicate that a cross-origin iframe is allowed to invoke the Web Authentication API's [[DiscoverFromExternalSource]](origin, options, sameOriginWithAncestors) method, specify the allow attribute on the iframe element and include the publickey-credentials-get feature-identifier token in the allow attribute's value. To override this default policy and indicate that a cross-origin iframe is allowed to invoke the Web Authentication API's [[DiscoverFromExternalSource]](origin, options, sameOriginWithAncestors) method, specify the allow attribute on the iframe element and include the publickey-credentials-在允许属性的值中获取特征标识符标记。

https://www.w3.org/TR/webauthn-2/#sctn-iframe-guidance https://www.w3.org/TR/webauthn-2/#sctn-iframe-guidance

Expanding on Tim's answer, the site embedding the RP will need to add the following allow attribute:扩展蒂姆的回答,嵌入 RP 的站点将需要添加以下allow属性:

<iframe src="..." allow="publickey-credentials-get *" />

The spec is a little ambiguous about this, but digging into Permissions Policy a bit I believe the RP also needs to set the following HTTP header in the response to the URL specified in the iframe's src :规范对此有点模棱两可,但稍微深入研究一下权限策略,我相信 RP 还需要在对 ZE6B391A8D2C4D45703D 中指定的 iframe 的响应中设置以下 HTTP src

Permissions-Policy: publickey-credentials-get=*

If you want more granular control you can whitelist specific URLs that are allowed to embed the RP's site:如果您想要更精细的控制,您可以将允许嵌入 RP 站点的特定 URL 列入白名单:

# Only specific sites
Permissions-Policy: publickey-credentials-get=("https://example.com")

With https://example.com being the URL of the page that's embedding the RP's site in the <iframe> https://example.com是在<iframe>中嵌入 RP 站点的页面的 URL

Once both pieces are in place I think you'll be able to trigger navigator.credentials.get() in the iframe.一旦两个部分都到位,我认为您将能够在 iframe 中触发navigator.credentials.get()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM