OpenAPITools / OpenAPITools/openapi-generator

[Question] : How to integrate authentication (perhaps using passportjs) into auto-generated node express service code

Open
#9,917 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

I am trying to figure out the "standard" way that javascript developers integrate authentication (perhaps using passportjs) into an (OpenAPITools) auto-generated node express service backend.

I understand that passport supports many strategies. Currently I am looking for integration of the JWT strategy into my auto-generated node express service. I am assuming that many have done this. I am looking for documentation (either from the openapi tools team, or the community of users) that might illustrate how this is done.

The kinds of online resources that relate to this include the following:
https://helabenkhalfallah.medium.com/nodejs-rest-api-with-express-passport-jwt-and-mongodb-98e5f2fee496

This is almost exactly reflective of my desired backend architecture (Node Express, Mongo, Passport w/ JWT). However the linked description does not include the one element that is at the core of my service design: the fact that the service code (and its stubs) is autogenerated by the OpenAPI code generation tools.

I already have a working backend service that was created through the use of the OpenAPI tools. Until now I've not locked down any of the route endpoints. I am looking at the cleanest way to add the passport enabled authentication framework (using a JWT strategy) to this already working service code.

I am also quite open to the thought that perhaps passportjs is NOT the best way to integrate authentication into node express code generated by the OpenAPITools. If there is a better, already integrated, alternative, please let me know. I'm even open to authentication alternatives that are not JWT (e.g. OAUTH2). However I do think the passport flexibility and JWT (as a starting point strategy), are attractive.

Any information/guidance would be appreciated.

P.S.

I did notice that the generated service code includes the following two routes:


    this.app.get('/login-redirect', (req, res) => {

      res.status(200);

      res.json(req.query);

    });

    this.app.get('/oauth2-redirect.html', (req, res) => {

Its not clear to me how to leverage these, they are certainly related to my concern for integration of a proper authentication mechanism.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with docs/generators/nodejs-express-server.md and inspect the generated /login-redirect and /oauth2-redirect.html routes mentioned in the issue. The request seeks guidance for integrating Passport JWT or OAuth2 into generated Node Express code, but it provides no specific documentation change or completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, mongodb, node.js
Domain
api, authentication, backend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.