php - Symfony Websockets: Logged User always returns anonym within Topic -
i found problem - can't explain well. webserver , websocket server running on "127.0.0.1:xyz" each. when access website "127.0.0.1:xy/app_dev.php/account" , working, cookies sent, read , logged in user given clientmanipulator.
when access website "localhost:xy/app_dev.php/account", anonymous user , cookies not sent. can explain me please - , have affects in production mode ? (e.g. user can connect ip of website - , bring me same problem, wouldn't ? )
this question related this one. (symfony 2.7)
i have implemented gos websocket bundle , can send messages in realtime channels, users can subscribe to. problem is, don't have access logged in user within notification topic class. tried subscribed in related post linked to.
currently, injecting "@security.token_storage" topic - said behaviour same other approaches too. think "cookie / domain" problem, cookies not sent websocket server. here configuration:
symfony / php webserver: "server running on http://127.0.0.1:8000"
gos websocket config.yml:
gos_web_socket: server: port: 8081 #the port socket server listen on host: 127.0.0.1 #the host ip bind router: resources: - @messagebundle/resources/config/pubsub/routing.yml client: firewall: main session_handler: @session.handler.pdo pushers: zmq: host: 127.0.0.1 port: 5555 persistent: true protocol: tcp @session.handler.pdo in services.yml:
pdo: class: pdo arguments: dsn: mysql:host=%database_host%;port=%database_port%;dbname=%database_name% user: %database_user% password: %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}] framework session configured use pdo handler:
session: # handler_id set null use default session handler php.ini handler_id: session.handler.pdo javascript part connect client websocket:
var websocket = ws.connect("ws://127.0.0.1:8000"); websocket.on("socket/connect", function(session){ session.subscribe("account/notification", function(uri, payload){ console.log("received message", payload.msg); }); }); this configuration, token storage gets injected in service notification topic. "onsubscribe" method of topic gets hit, user stays anonymous, if logged in:
public function onsubscribe(connectioninterface $connection, topic $topic, wamprequest $request) { // returns anonym dump($this->tokenstorage->gettoken()->getuser());die; } what did miss ?
regards.
as clear, explanation resides in http cookies limitations. find more details here: http://www.cookiecentral.com/faq/#4.3
"the main limit on retrieving cookie can retrieve cookies valid document script resides in. is, script on www.myserver.com cannot read cookies www.yourserver.com."
also, suggest ensure running websocket server on "localhost" domain access website using "localhost". doing so, both domains still in accordance.
as question myself, have never checked if accessing website address (127.0.0.1) , having websocket server running on "localhost" trigger same issue. anyway, answer you, no, should not reproduce once in prod, have right domain (not ip).
however, answer thomas not right, cannot run both servers on same port, definition ports (one port, 1 service/process): https://en.wikipedia.org/wiki/port_%28computer_networking%29 .
Comments
Post a Comment