OKTA 快速中间件 - TypeError [ERR_INVALID_ARG_TYPE]:"original" 参数必须是函数类型。接收类型未定义

OKTA express middleware - TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type Function. Received type undefined

仅在应用中包含以下内容会导致以下错误。

const { ExpressOIDC } = require('@okta/oidc-middleware');

完整错误:

$ node app.js 
internal/util.js:257
    throw new ERR_INVALID_ARG_TYPE('original', 'Function', original);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type Function. Received type undefined
    at promisify (internal/util.js:257:11)
    at Object.<anonymous> (/dev/tmpOidc/node_modules/jose/lib/jwk/key/rsa.js:13:25)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/dev/tmpOidc/node_modules/jose/lib/jwk/import.js:9:16)

重现步骤 1.新建一个node app,添加express和Okta的oidcmiddleware

npm init
npm install express --save
npm install --save @okta/oidc-middleware
  1. 创建app.js
const express = require('express')
const app = express()
const port = 3000

// const { ExpressOIDC } = require('@okta/oidc-middleware');

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))

  1. 运行它
node app.js

看看如何 运行s。最后,取消注释并包含设置 OIDC 中间件的行。

const { ExpressOIDC } = require('@okta/oidc-middleware');

运行 再次打开应用程序,出现上面的错误。

已解决:需要 运行 节点 v12 而不是 v10

我刚刚发布了一篇 YouTube video,向您展示了如何使用 Okta 的 OIDC 中间件。

您可以找到我使用的步骤 here。总结:

  1. 使用 express-generator 和 pug 创建一个新项目:npx express-generator --view=pug
  2. 在 Okta 上添加一个新的 web 应用程序,使用 http://localhost:3000/callback 作为登录重定向 URI
  3. 安装 Schematics CLI:npm install -g @angular-devkit/schematics-cli
  4. 使用您的 Okta 值安装和 运行 OktaDev 示意图:
npm i @oktadev/schematics
schematics @oktadev/schematics:add-auth --issuer=$issuer --clientId=$clientId -- 
clientSecret=$clientSecret
  1. 启动您的应用并使用 Okta 进行身份验证:npm start

您可以在 this GitHub repo 中看到这些步骤的结果。

已解决。当我发布我的问题时,我应该包括系统信息,例如 Node.js 的版本。我有 v10.8.0。一旦我更新到 v12,类型错误就消失了。