Giter Site home page Giter Site logo

Comments (3)

panva avatar panva commented on August 25, 2024

Of course passing the authenticate call into every single resource middleware chain is going to fail on you - the strategy is for starting and consuming an authorization request and response callback. Nothing more.

Is this how I am supposed to protect an endpoint when using with passport?

Please consult the passport documentation for this.

My read of the code is that because id_token is not set, this method won't ever return a defined value.

if (error) throw;
if (id_token) validate(); // implicit and hybrid response types
if (code) finish validate() from before and then do tokenEndpoint();

I can see that when none of these is present no promise is returned, i will fix that with a rejection that the received data does not seem like an OIDC response or something similar. That ain't going to fix your issue of using passport in an incorrect way.

from node-openid-client.

morungos avatar morungos commented on August 25, 2024

Aha! So, in order to use with passport, I need to protect the endpoints entirely separately, with something like:

function checkAuthentication (options) {
  return function (req, res, next) {
    if (req.isAuthenticated()) {
      return next()
    }
    res.redirect((options || {}).loginRedirect || '/');
  }
}
router.use(checkAuthentication());

That does seem to move it forward. Passport's documentation isn't exactly wonderful, and without an example that does seem to be a gap here. I'll maybe see if I can work out an example I can make in a PR if you're interested.

from node-openid-client.

panva avatar panva commented on August 25, 2024

Any and all improvements, additions, typo fixes and such contributions are indeed very welcome. Happy to hear you're progressing.

from node-openid-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.