我目前正在尝试构建一个express服务器,允许用户通过两个第三方服务进行身份验证: Google和Steam。身份验证是通过JWT完成的,当两个服务中只有一个被激活时,它就可以工作,但是当用户使用这两个服务中的一个登录时,我无法让受保护的路由工作。
代码:
const express = require('express');
const bodyParser = require('body-parser');
const {gAuth, gProtect} = require('./auth/google_auth');
const {sAuth, sProtect} = require('./auth/steam_auth');
const app = express();
gAuth(app);
sAuth(app);
//middlewares
app.use(express.static('views'));// folder in which to put the static files (html, css, js client)
app.use(bodyParser.json({limit: '50mb'})); // read json
//middlewares (just for the widget)
app.use(bodyParser.urlencoded({ extended: true , limit: '50mb'})); // read form enctype data
app.set('view engine', 'ejs'); // set the engine render ejs for dynamic building of html pages with ejs tags
//set up routers for v1 app
const genericRouter = require('./routes/generic_router'); //testing if the application is working
const secureRouter = require('./routes/secure_router'); //testing if normal auth is working
//set up routers for latest version app
app.use('/', genericRouter);
app.use('/', gProtect(), secureRouter);//protected end-points (requiring auth)
app.use('/', sProtect(), secureRouter);
module.exports = app;问题出在
app.use('/', gProtect(), secureRouter);//protected end-points (requiring auth)
app.use('/', sProtect(), secureRouter);位,因为第二个app.use覆盖了第一个,使得Google的所有身份验证尝试都失败。我可以做些什么来使用户可以使用Google或Steam访问受保护的路由?
发布于 2020-02-01 08:55:46
使用不同的端点
app.use('/', genericRouter);
app.use('/google', gProtect(), secureRouter);
app.use('/steam', sProtect(), secureRouter);https://stackoverflow.com/questions/60012076
复制相似问题