TypeError,未定义的“摘要”,在开发环境中

Pea*_*ler 8 auth0

当我们为 localhost 构建 Angular SPA 时,它运行良好。

在我们的开发环境中,此错误会蔓延到 DevTool 控制台并破坏一切:错误错误:未捕获(承诺):类型错误:无法读取未定义的属性“摘要”

TypeError: Cannot read property 'digest' of undefined
    at N (auth0-spa-js.production.js:1)
    at ie.<anonymous> (auth0-spa-js.production.js:1)
    at Generator.next (<anonymous>)
    at auth0-spa-js.production.js:1
    at new ZoneAwarePromise (zone-evergreen.js:876)
    at t (auth0-spa-js.production.js:1)
    at ie.loginWithRedirect (auth0-spa-js.production.js:1)
    at AuthGuard.<anonymous> (auth.guard.ts:22)
    at Generator.next (<anonymous>)
    at fulfilled (environment.ts:11)
    at resolvePromise (zone-evergreen.js:797)
    at new ZoneAwarePromise (zone-evergreen.js:879)
    at t (auth0-spa-js.production.js:1)
    at ie.loginWithRedirect (auth0-spa-js.production.js:1)
    at AuthGuard.<anonymous> (auth.guard.ts:22)
    at Generator.next (<anonymous>)
    at fulfilled (environment.ts:11)
    at ZoneDelegate.invoke (zone-evergreen.js:359)
    at Object.onInvoke (core.js:34195)
    at ZoneDelegate.invoke (zone-evergreen.js:358)
Run Code Online (Sandbox Code Playgroud)

我想这一定是关于构建过程,一些不同的标志,但我无法确切地弄清楚是哪个。

Hoo*_*cat 24

这可能是因为您的开发服务器设置为不安全的来源。

digest可能指window.crypto.subtle.digest的的网络加密API。如果您使用的是基于 Chromium 的浏览器,根据此处Chromium 项目页面,该subtle属性只能在安全来源中使用:

对 WebCrypto API 的访问仅限于安全来源(即 https:// 页面)。

注意:在规范中,crypto.subtle 在不安全的上下文中应该是未定义的

因为digest是 的一种方法subtle,并且subtleundefined,所以您会收到此错误。

我们在使用auth0-spa-js 库时遇到了同样的错误。它在 localhost 上工作,而不是在我们的 http 临时站点上工作,但在我们的生产 https 站点上还可以。

如果您不在安全来源中,请尝试使您的开发环境安全,然后再次测试(应该使用自签名证书)。提醒一下,安全来源是:

哪些来源是“安全的”?

安全源是那些至少匹配以下(方案、主机、端口)模式之一的源:

  • (https, *, *)
  • (wss, *, *)
  • (*, 本地主机, *)
  • (*, 127/8, *)
  • (*, :: 1/128, *)
  • (文件, *, -)
  • (镀铬扩展,*,—)

也就是说,安全源是从本地机器(必须是可信的)或通过网络从经过加密验证的服务器加载资源的源。

我不确定Auth0团队是否有一个在非安全来源中工作的 SPA 库(或计划在他们最新的 SPA 库中启用该功能),但他们的原生 JS 库肯定有。