2016-09-28 47 views
0

我想安装谷歌AUTH的Hapi.js项目,我不明白为什么我登陆后得到一个重定向循环回到我的登录路由。Hapi.js贝尔/验证cookie的重定向循环

这只会在用户尚未登录到他们的Google帐户或尚未授予应用程序访问其信息的权限时发生。

这是身份验证注册码

server.auth.strategy('session', 'cookie', true, { 
    password: 'private_key', 
    redirectTo: '/login/google' 
}); 

server.auth.strategy('google', 'bell', { 
    provider: 'google', 
    password: 'private_key', 
    clientId: 'client_id', 
    clientSecret: 'client_secret', 
    location: 'same_origin_registered_with_google' 
}); 

这些都是我的两条路线

server.route({ 
    method: ['GET', 'POST'], 
    path: '/login/google', 
    config: { 
     auth: { 
      strategy: 'google', 
      mode: 'try' 
     }, 
     plugins: { 'hapi-auth-cookie': { redirectTo: false } }, 
     handler: (request, reply) => { 
      if (!request.auth.isAuthenticated) { 
       return reply('Authentication failed due to: ' + request.auth.error.message); 
      } 

      let creds = request.auth.credentials; 

      request.cookieAuth.set({ 
       token: creds.token, 
       userId: creds.profile.id 
      }); 

      return reply.redirect('/'); 
     } 
    } 
}); 

server.route({ 
    method: 'GET', 
    path: '/', 
    handler: (request, reply) => { 
     return reply('hello'); 
    } 
}); 

要注意,AUTH的cookie被设定,一旦重定向退出循环我可以导航到“/”路径手动没有问题。

任何帮助,这是非常赞赏

回答

4

这是由于hapi-auth-cookie尚未与isSameSite cookie的选项买卖高致病性禽流感15造成的cookie不被发送回服务器。

您可以通过手动设置选项来解决此问题。

更多信息,可以在高致病性禽流感15日发布中找到笔记https://github.com/hapijs/hapi/issues/3323hapi-auth-cookiehttps://github.com/hapijs/hapi-auth-cookie/pull/142

+0

不知道为什么维护者不合并这个PR。 – Subin

+0

@Subin PR现在合并:D –

+0

是否有任何安全漏洞做isSameSite Lax? –

0

的PR这解决问题:

server.auth.strategy('session', 'cookie', true, { 
    password: 'private_key', 
    redirectTo: '/login/google', 
    isSameSite: 'Lax' 
});