使用无需状态/会话的passport.js(Google OpenID connect)
我正在尝试使用无状态的Passport-openidconnect,但不确定为什么它不起作用。我有这个为google-oauth2工作。我尝试指定state = false,但它一直在抱怨状态。谁能告诉我我做错了吗?
错误是:
Error: OpenID Connect authentication requires session support when using state. Did you forget to use express-session middleware?
at SessionStore.store (/home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/state/session.js:39:39)
at /home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/strategy.js:336:28
at Strategy.manual [as _setup] (/home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/setup/manual.js:23:12)
at Strategy.authenticate (/home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/strategy.js:274:10)
at attempt (/home/nca/projects/oauth-test/node_modules/passport/lib/middleware/authenticate.js:361:16)
at authenticate (/home/nca/projects/oauth-test/node_modules/passport/lib/middleware/authenticate.js:362:7)
at Layer.handle [as handle_request] (/home/nca/projects/oauth-test/node_modules/express/lib/router/layer.js:95:5)
at next (/home/nca/projects/oauth-test/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/nca/projects/oauth-test/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/nca/projects/oauth-test/node_modules/express/lib/router/layer.js:95:5)
一些相关代码:
const oidcOpts = {
issuer: '',
authorizationURL: '',
tokenURL: '',
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: 'http://localhost:3001/oidccallback',
redirect_uri: 'http://localhost:3001/oidccallback',
state: false,
store: null,
};
passport.use(new OICStrategy(oidcOpts, (issuer, sub, profile, jwtClaims, accessToken, refreshToken, tokens, done) => {
console.log("-----------------------------")
console.log(accessToken);
}));
app.get('/login', passport.authenticate('openidconnect', {state: false, session: false}));
app.get('/callback', passport.authenticate('openidconnect', {state: false, session: false, "callback": true, failureRedirect: '/login'}), routes.openidCallback)
回答如下:It is not possible根据node-openid-client的作者
使用无需状态/会话的passport.js(Google OpenID connect)
我正在尝试使用无状态的Passport-openidconnect,但不确定为什么它不起作用。我有这个为google-oauth2工作。我尝试指定state = false,但它一直在抱怨状态。谁能告诉我我做错了吗?
错误是:
Error: OpenID Connect authentication requires session support when using state. Did you forget to use express-session middleware?
at SessionStore.store (/home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/state/session.js:39:39)
at /home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/strategy.js:336:28
at Strategy.manual [as _setup] (/home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/setup/manual.js:23:12)
at Strategy.authenticate (/home/nca/projects/oauth-test/node_modules/passport-openidconnect/lib/strategy.js:274:10)
at attempt (/home/nca/projects/oauth-test/node_modules/passport/lib/middleware/authenticate.js:361:16)
at authenticate (/home/nca/projects/oauth-test/node_modules/passport/lib/middleware/authenticate.js:362:7)
at Layer.handle [as handle_request] (/home/nca/projects/oauth-test/node_modules/express/lib/router/layer.js:95:5)
at next (/home/nca/projects/oauth-test/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/nca/projects/oauth-test/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/nca/projects/oauth-test/node_modules/express/lib/router/layer.js:95:5)
一些相关代码:
const oidcOpts = {
issuer: '',
authorizationURL: '',
tokenURL: '',
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: 'http://localhost:3001/oidccallback',
redirect_uri: 'http://localhost:3001/oidccallback',
state: false,
store: null,
};
passport.use(new OICStrategy(oidcOpts, (issuer, sub, profile, jwtClaims, accessToken, refreshToken, tokens, done) => {
console.log("-----------------------------")
console.log(accessToken);
}));
app.get('/login', passport.authenticate('openidconnect', {state: false, session: false}));
app.get('/callback', passport.authenticate('openidconnect', {state: false, session: false, "callback": true, failureRedirect: '/login'}), routes.openidCallback)
回答如下:It is not possible根据node-openid-client的作者