Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Management & User authentication #411

Open
tejadong opened this issue Mar 17, 2020 · 1 comment
Open

Session Management & User authentication #411

tejadong opened this issue Mar 17, 2020 · 1 comment
Labels

Comments

@tejadong
Copy link

Hello, I have an API (Symfony 3) that works with the following repository: https://gist.github.com/diegonobre/341eb7b793fc841c0bba3f2b865b8d66

It works using tokens and it works quite well. The jWe part of the GosWebSocketBundle client has been integrated into a test project in Angular 9 and the websocket is working correctly (it connects and sends messages between the client and the server). As for the authentication, if I do it using the Symfony form, I can detect the user's data from the websocket server without problems, but if I do it from angular I can't because the authentication works through the path /oauth/v2/token and this returns me the token I have to use on each next request so the server knows who I am and allows me to perform this task ... is there any way to get GosWebSocketBundle to detect login via path before mentioned in order to obtain the user's data in the websocket server in the same way as if I log in from the symfony login form?

@mbabker
Copy link
Contributor

mbabker commented Mar 17, 2020

I couldn't tell you to be honest if that approach is even possible out-of-the-box.

This bundle and the underlying Ratchet library expect to be able to share a session started in the main Symfony web application using a more conventional request/response workflow, that's being done by dispatching an event when a new websocket connection is established with the most pertinent bit at this part which is reading the data out of the session object created by Ratchet. If you're doing OAuth, then it sounds like you don't have a cookie with the session name in it and that's where Ratchet is having issues making the session functionality work.

Unfortunately the request info isn't available by the time it gets to this bundle's code, so I don't know if there would be a way for you to just replace the inbuilt authentication provider. Looking at ratchetphp/Ratchet#604 it seems one option might be to create your own replacement for Ratchet\Session\SessionProvider that can get the info you need to set up the session correctly, doing that is going to require you replace the gos_web_socket.server.builder service from this bundle with your own Gos\Bundle\WebSocketBundle\Server\App\ServerBuilderInterface implementation (you should be able to just copy the builder from this bundle and change the new SessionProvider() call to your custom class).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants