【问题标题】:hapi-auth-cookie not setting cookie immediately after redirect with bellhapi-auth-cookie 在使用铃铛重定向后未立即设置 cookie
【发布时间】:2016-11-24 13:19:51
【问题描述】:

我将 Bell 用于 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 就在那里。一旦我获得访问权限,它就可以正常工作;只是最初的允许。发生了什么?

【问题讨论】:

    标签: cookies oauth-2.0 hapijs


    【解决方案1】:

    尝试将“isSameSite”变量设置为“Lax”值

    const options = {
        connections: {
            state: {
                isSameSite: 'Lax'
            }
        }
    };
    
    const server = new Server(options);
    

    【讨论】:

      猜你喜欢
      • 2014-10-10
      • 2013-12-27
      • 1970-01-01
      • 2016-02-24
      • 2016-11-27
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      相关资源
      最近更新 更多