douyin8809 2017-10-30 14:15
浏览 62
已采纳

在Symfony应用程序之间共享会话

I have an old Symfony 2.4 app (with php 5) and a standard security (form_login firewall & role based authorization). Let's call it app1.

Now I'm creating a new Symfony 3.3 app (php 7) that I'd like to use keeping sessions so users can switch from one to an other seamlessly. Let's call it app2. The users' authentication and storage would still be managed by app1.

These apps are hosted on the same domain, different subdomains. I managed to share the app1 session files into app2 (with Docker volumes).

Here is the session configuration of both apps:

framework:
    session:
        handler_id: session.handler.native_file
        save_path: '%kernel.root_dir%/../var/sessions/%kernel.environment%'
        cookie_domain: myapp.dev

So when I'm logged into app1 I'm expecting to be considered logged into app2 as well.
I'm seeing app2 sending the right cookie but it crashes saying :

Warning: Class __PHP_Incomplete_Class has no unserializer

It is actually trying to unserialize app1's user from the session but does not have the related User implementation in app2.

How can app2 know that I'm logged in app1 ?

  • 写回答

1条回答 默认 最新

  • dtqie02844 2017-10-30 16:26
    关注

    Obviously you can't share session files without sharing the classes, which is hardly an option considering a gap between versions.

    In general case you would need to use one of single sign on systems - OAuth2, OpenId, etc. e.g. https://github.com/FriendsOfSymfony/FOSOAuthServerBundle

    Alternatively you can do it manually, which will require a bit more coding, but can be tailored to your needs and potentially smaller operational costs. In this case your app1 should provide an API to return user info by sessionId, and app2 should implement custom authentication to query this API. The API should not be exposed, and be available only to the app2 container.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀