简体   繁体   中英

Symfony session, different route, different session

So, i have two differents route on my project :

/memberarea
/mobile

The first is for the web version on my application, and the second is for the mobile version.

Here you can see a part of my security.yml :

firewalls:
    main:
        pattern: ^/
        form_login:
            login_path: /
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            default_target_path: /memberarea
        logout:       true
        anonymous:    true
    mobile:
        pattern: /mobile/.*
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/memberarea, roles: IS_AUTHENTICATED_FULLY }
    - { path: ^/mobile, roles: IS_AUTHENTICATED_FULLY }

My problem, when a user login on mobile, i create a session on symfony with the firewall mobile like : $token = new UsernamePasswordToken($user, $request->get('password'), "mobile", $user->getRoles());.....

this user can use all route in /mobile , it's ok. But he can use /memberarea too. How can i do for login a user just for /mobile , just for /memberarea or for both ?

If I have correctly understood, you want to log into your mobile application with a different session than on your web application.

What I am doing in order to obtain this result is setting up in my security.yml file a different context for each firewall I have.

(If you want to have one session for both you must have the context with the same value for the given firewalls.)

File: app/config/security.yml

firewalls:
  main:
      pattern: ^/
      **context: user**
      form_login:
          login_path: /
          provider: fos_userbundle
          csrf_provider: form.csrf_provider
          default_target_path: /memberarea
      logout:       true
      anonymous:    true
  mobile:
      pattern: /mobile/.*
      *context: mobile_user*
      logout:       true
      anonymous:    true

Hope this helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM