Search code examples
node.jsnestjsopenid

Unknown authentication strategy "oidc" with openid-client and passport in NestJS


I am following this article to implement OIDC login in NestJS. But I'm stuck and don't know how to proceed. I have done what the article describes, and it works to the point that I get redirected to enter my username and password, but when I get directed back to my app, to the path /auth/callback instead of showing my app being logged in, it shows a blank page with only the characters {}. When I investigate the back end, I can see the following error:

GeneralExceptionFilter: Error: Unknown authentication strategy "oidc"
    at attempt (/Users/roberto/dev/ps360/packages/app/node_modules/passport/lib/middleware/authenticate.js:193:39)
    at authenticate (/Users/roberto/dev/ps360/packages/app/node_modules/passport/lib/middleware/authenticate.js:370:7)
    at Object.use (/Users/roberto/dev/ps360/node_modules/@nestjs/core/middleware/utils.js:51:24)
    at /Users/roberto/dev/ps360/node_modules/@nestjs/core/router/router-proxy.js:9:23
    at /Users/roberto/dev/ps360/node_modules/@nestjs/core/middleware/middleware-module.js:157:28
    at Layer.handle [as handle_request] (/Users/roberto/dev/ps360/node_modules/@nestjs/platform-express/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/roberto/dev/ps360/node_modules/@nestjs/platform-express/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/roberto/dev/ps360/node_modules/@nestjs/platform-express/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/roberto/dev/ps360/node_modules/@nestjs/platform-express/node_modules/express/lib/router/layer.js:95:5)
    at /Users/roberto/dev/ps360/node_modules/@nestjs/platform-express/node_modules/express/lib/router/index.js:281:22

I have been spinning my wheels and Google hasn't resulted in any leads. Does anyone have any ideas?


Solution

  • I figured out the problem. I'm answering my own question in case someone else gets this rare problem.

    For some reason there was a rogue version of passport that was installed, even though the package.json was only asking for "passport": "^0.4.1" there was a rogue copy of passport v0.5.2 in the node_modules. I can't explain how it ended up there. Regardless, it caused some mismatch that prevented @nestjs/passport being able to register the authentication strategy properly because of this.