我正在使用 node.js、express.js 和 node-oidc-provider 设置 OpenID Connect 提供程序。我一直在研究 https://github.com/panva/node-oidc-provider-example/tree/master/03-oidc-views-accounts 中的示例。 ,但它从不处理失败的身份验证。如果用户输入错误的密码,如何将用户重定向回登录页面?
expressApp.get('/interaction/:grant', async (req, res) => {
// The initial route hit by the client (Relying Party) that renders the login view if needed.
...
});
expressApp.post('/interaction/:grant/login', parse, (req, res, next) => {
User.authenticate(req.body.email, req.body.password)
.then((users) => {
// returns an array of user objects that match the credentials
if(!users.length)
{
// What now? I can't just redirect back to /interaction/:grant - I get session not found
}
// the rest works well enough (for now)....
...
}).catch(next);
});
最佳答案
就像在任何 Express 应用程序中一样。这样想吧。仅成功解决交互,否则如果您希望退出交互并将控制权返回给客户端,则会出错。
我倾向于单独开发交互,并且只在完成后将它们插入 oidc-provider。
关于node.js - 如何在 node-oidc-provider 中重定向失败的登录尝试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54699216/