简体   繁体   English

node-oidc-provider 的路由问题

[英]problem with routes with node-oidc-provider

I'm just starting with oidc-provider and I can't get express to recognize routes once I include oidc-provider.我刚从 oidc-provider 开始,一旦包含 oidc-provider,我就无法快速识别路线。

In the simple setup below, I get a "unrecognized route on '/'. The well known url for setup does work, and the auth endpoint looks like it does as well.在下面的简单设置中,我得到一个“'/' 上无法识别的路由。众所周知的设置 url 确实有效,并且 auth 端点看起来也一样。

const express = require('express');
const Provider = require('oidc-provider').Provider;

const app = express();

const configuration = {
  // ... see /docs for available configuration
  clients: [{
    client_id: 'foo',
    client_secret: 'bar',
    redirect_uris: ['http://192.168.128.128:3000/oidc/cb'],
    // ... other client properties
  }],
};

const oidc = new Provider('http://localhost:3000', configuration);

app.use('/oidc', oidc.callback());

app.get('/', function(req, res) {
        res.send('hello world');
});

oidc.listen(3000, () => {
  console.log('oidc-provider listening on port 3000, check http://localhost:3000/.well-known/openid-configuration');
});

I don't understand the whole "mount" notion though I suspect it has something to do with my route problem.尽管我怀疑它与我的路线问题有关,但我不理解整个“安装”概念。 Why is this happening?为什么会这样? What is the solution?解决办法是什么?

This is because you are doing:这是因为你在做:

oidc.listen(...) 

And by doing that, you are ignoring all the routes added to app .通过这样做,您将忽略添加到app的所有路由。 What you should do instead is to make the express app to listen, instead of the oidc provider:你应该做的是让 express 应用程序来监听,而不是 oidc 提供程序:

app.listen(...)

🙂 🙂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM