Search code examples
node.jsexpressmiddlewareokta

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


Just including the following in an app causes the following error.

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

Full error:

$ 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)

Steps to reproduce 1. Create a new node app and add express and Okta's oidc middleware

npm init
npm install express --save
npm install --save @okta/oidc-middleware
  1. Create 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. Run it
node app.js

See how it runs. Finally, uncomment and include the line that sets up the OIDC middleware.

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

Run the app again and I get the error above shows up.

Solved: Need to run with node v12 not v10


Solution

  • I just published a YouTube video that shows you how to use Okta's OIDC Middleware.

    You can find the steps I used here. To summarize:

    1. Create a new project with express-generator and pug: npx express-generator --view=pug
    2. Add a new web app on Okta with http://localhost:3000/callback as the login redirect URI
    3. Install Schematics CLI: npm install -g @angular-devkit/schematics-cli
    4. Install and run OktaDev Schematics with your Okta values:
    npm i @oktadev/schematics
    schematics @oktadev/schematics:add-auth --issuer=$issuer --clientId=$clientId -- 
    clientSecret=$clientSecret
    
    1. Start your app and authenticate with Okta: npm start

    You can see the result of these steps in this GitHub repo.