如何修复 Authany SDK 中的 SubtleCrypto: digest() undefined 错误¶
Authany SDK 使用了浏览器 API SubtleCrypto: digest(),该 API 要求使用 HTTPS。因此,如果您使用该 SDK 的客户端应用运行在 HTTP(非安全)环境下,就可能遇到 SubtleCrypto: digest() 非 HTTPS/安全上下文错误。
要使用该 SDK,您的客户端应用必须运行在 HTTPS 下,或运行在安全上下文中。安全上下文包括从 localhost 或 127.0.0.1 运行应用的情况。
以下是在 Chrome 和 Firefox 中出现 SubtleCrypto: digest() 非 HTTPS/安全上下文错误时得到的错误消息示例。
Chrome
{
"stack": "TypeError: Cannot read properties of undefined (reading 'digest')\n at http://mycompany.com/index.9bf4411c.js:1:219150\n at p (http://mycompany.com/index.9bf4411c.js:1:148005)\n at o._invoke (http://mycompany.com/index.9bf4411c.js:1:147765)\n at Generator.next (http://mycompany.com/index.9bf4411c.js:1:148364)\n at e_ (http://mycompany.com/index.9bf4411c.js:1:145029)\n at i (http://mycompany.com/index.9bf4411c.js:1:145227)\n at http://mycompany.com/index.9bf4411c.js:1:145288\n at new Promise (<anonymous>)\n at http://mycompany.com/index.9bf4411c.js:1:145168\n at iz (http://mycompany.com/index.9bf4411c.js:1:219441)",
"message": "Cannot read properties of undefined (reading 'digest')"
}
Firefox
{
"fileName": "http://you-app-url.com/index.9bf4411c.js",
"lineNumber": 1,
"columnNumber": 219125,
"message": "window.crypto.subtle is undefined"
}
修复方法¶
以下是修复 SubtleCrypto: digest() 非 HTTPS/安全上下文错误的方法:
- 如果您需要在无法设置 HTTPS 的本地环境或测试环境中运行应用,可以考虑在安全上下文中运行应用,例如 http://localhost 或 http://127.0.0.1。
- 如果要从非 localhost 的其他域名运行应用,请在该域名上设置 HTTPS。
要了解更多关于 SubtleCrypto: digest() 和安全上下文的信息,请参阅以下链接页面: