Guard创建会话异步

时间:2016-01-12 15:36:58

标签: symfony

我使用guard进行用户身份验证,登录由html fetch api处理。

如果登录成功,我将获取js auth的令牌给api,但我希望在页面更新用户登录后,但不是。

作为回应,我看到PHPSESSID和REMEMBERME的设置cookie,但看起来这个cookie没有保留。

我不确定,哪里可能有问题,看起来警卫让他的工作很好。

请求不是跨域。

请求标题:

GET /login/check-facebook?code=xxx HTTP/1.1
Pragma: no-cache
Cache-Control: no-cache
accept: application/json
content-type: application/json
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36
x-api-token: anon.
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en,cs;q=0.8,en-US;q=0.6
DNT: 1

响应标题:

HTTP/1.1 200 OK
Server: nginx/1.8.0
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.6.16
Set-Cookie: PHPSESSID=xxx; path=/; HttpOnly
Cache-Control: no-cache
X-Debug-Token: edb1db
X-Debug-Token-Link: /_profiler/edb1db
Date: Tue, 12 Jan 2016 15:12:32 GMT
Set-Cookie: REMEMBERME=xxx; expires=Tue, 19-Jan-2016 15:12:32 GMT; Max-Age=604800; path=/; httponly

防火墙:

      main:
        provider: db_provider
        stateless:  false
        remember_me:
          secret: "%secret%"
          lifetime: 604800 # 1 week in seconds
          path:     /
          always_remember_me: true
        pattern:    ^/
        anonymous: ~
        logout: ~
        guard:
          authenticators:
              - authenticator.facebook
              - authenticator.email
          entry_point: authenticator.facebook

1 个答案:

答案 0 :(得分:0)

安排它。

在fetch api中,必须设置credentials: 'same-origin'选项。

类似的东西必须用jquery或xhr发送。 withCredentials: true