2

I use symfony 3.3 and WebSocketBundle for socket messaging and notification system. Also was used FOS oAuth and FOS user bundle for auth part of application.

Question: I want get user in Topic. I try to config session sharing...
All works fine.. But this totorial was shared php session. In my project I used oAuth session (with oAuth access tockens) and I want get user from oAuth session.. How I can do that?

security:
encoders:
    FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username_email

firewalls:
    socket:
        pattern: ^/test/socket
        anonymous:    false
        fos_oauth:  true
    public:
        methods: [POST]
        pattern: ^/api/v1/users
        security: false
    oauth_token:
        pattern:    ^/oauth/v2/token
        security:   false

    oauth_authorize:
        pattern:    ^/oauth/v2/auth
        form_login:
            provider: fos_userbundle
            check_path: fos_user_security_check
            login_path: fos_user_security_login
    api:
        pattern:    ^/api
        fos_oauth:  true
        stateless:  true
        anonymous:  true # can be omitted as its default value

GOSWebSocketBundle Config

gos_web_socket:
server:
    port: 8080        #The port the socket server will listen on
    host: 127.0.0.1   #The host ip to bind to
    router:
        resources:
            - '@WebSocketsBundle/Resources/config/pubsub/routing.yml'
client:
    firewall: socket #can be an array of firewalls
    session_handler: '@session.handler.pdo'

framework: session: handler_id: session.handler.pdo

Services:

services:
ws.topic.messages:
    class: WebSocketsBundle\Topic\ChatTopic
    arguments:
        - '@gos_web_socket.websocket.client_manipulator'
    tags:
        - { name: gos_web_socket.topic }
pdo:
    class: PDO
    arguments:
        - 'mysql:host=%database_host%;port=%database_port%;dbname=%database_name%'
        - '%database_user%'
        - '%database_password%'
    calls:
        - [ setAttribute, [3, 2] ] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION

session.handler.pdo:
    class:     Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
    arguments:
      - '@pdo'
      - { lock_mode: 0}
Deim Jons
  • 21
  • 1

0 Answers0