我正在使用Bell for Meetup OAuth,然后继续使用hapi-auth-cookie。
以下是代码的相关部分。
server.auth.strategy('session', 'cookie', {
cookie: 'sessionid',
password: '32_char_password',
// redirectTo: '/login', //this causes a loop immediately after allowing access
redirectTo: false,
isSecure: false,
});
server.auth.strategy('meetupauth', 'bell', {
provider: 'meetup',
password: '32_char_password',
isSecure: false,
providerParams: {
set_mobile: 'on'
},
clientId: 'client_id',
clientSecret: 'client_secret',
});
server.route({
method: ['GET'],
path: '/login',
config: {
auth: 'meetupauth',
handler: (request, reply) => {
request.cookieAuth.set({
sid: request.auth.credentials.profile
});
return reply.redirect('/user');
}
}
});
server.route({
method: 'GET',
path: '/user',
config: {
auth: 'session',
handler: (request, reply) => reply('My Account'),
}
});
代码工作正常,但允许访问Meetup后立即生效。允许访问后,/login
页面会重定向到/user
。没有重定向回登录页面,我得到401,在我重新加载/user
后,cookie就在那里。一旦我获得访问权限,它就可以正常工作;只是最初的允许。发生了什么事?
答案 0 :(得分:1)
尝试设置" isSameSite"变量为" Lax"值
const options = {
connections: {
state: {
isSameSite: 'Lax'
}
}
};
const server = new Server(options);