【问题标题】:TypeError, 'digest' of undefined, in development environmentTypeError,未定义的“摘要”,在开发环境中
【发布时间】:2019-11-30 11:04:14
【问题描述】:

当我们为 localhost 构建 Angular SPA 时,它可以完美运行。

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

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)

我想这一定是关于构建过程的一些东西,一些不同的标志,但我无法确定到底是哪个。

【问题讨论】:

    标签: auth0


    【解决方案1】:

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

    digest 可能指的是Web Crypto API 中的window.crypto.subtle.digest。如果您使用的是基于 Chromium 的浏览器,根据Chromium Projects page here,subtle 属性只能在安全源中使用:

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

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

    因为digest 是subtle 的方法,而subtle 是undefined,所以会出现此错误。

    我们在使用auth0-spa-js library 时遇到了同样的错误。它在 localhost 上运行,而不是在我们的 http 暂存站点上,但在我们的生产 https 站点上正常。

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

    哪些来源是“安全的”?

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

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

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

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

    【讨论】:

      【解决方案2】:

      角度框架: 通过为应用程序的 nginx(nginx.conf 或 app.conf)配置 SSL 证书来获取 HTTPS 可以解决此问题。 为您的域分配 ssl 证书和 ssl 密钥。确保将端口更改为 443。

      【讨论】:

      • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
      【解决方案3】:

      这似乎比 Auth0 与 Angular 更相关,但出于好奇,您是否在组件中定义了 digest?

      如果没有,您可以在组件级别使用:digest: {};。

      我希望这对您的探索有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-19
        • 2017-05-09
        相关资源
        最近更新 更多