-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Using Laravel's built-in session authentication instead of collaborators and tokens #4
Comments
The session won't work because there is no client/websocket connection to the laravel server but only to the hocuspocus server. The hocuspocus server, via the webhook extension, is in charge of actually updating the document (database table) and this is also authenticated via the same token. Note: I am not the creator or maintainer of this package, but we do use it in a 'close-to-production' setting. |
My understanding is that the onconnected hook on the hocus-pocus server is passed via the websocket extension to the laravel server, where you can authenticate or return 401. If 401 is returned by the laravel server the user is also blocked from the hocus-pocus server.
If the session key was included in the payload the same way the access token currently is, you could use the session to authenticate the user?
…On Mon, 23 Jan 2023, 14:54 Jan Misker, ***@***.***> wrote:
The session won't work because there is no client/websocket connection to
the laravel server but only to the hocuspocus server.
The hocuspocus server, via the webhook extension, is in charge of actually
updating the document (database table) and this is also authenticated via
the same token.
Note: I am not the creator or maintainer of this package, but we do use it
in a 'close-to-production' setting.
—
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB6COEJFUGLD2EGYHYOVXILWTZ5Q7ANCNFSM6AAAAAAUDU6UHQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Indeed, basically there are 2 points of authorization: 1) onConnected, and 2) onChange (with a delay) to store the document back to the database. Both via callbacks to this extension. I guess the tricky part with using a session token is what happens when the token expires. How to provide a new session token? But as said, I didn't create this package, I hope the authors also respond. |
Exactly. When it expires the server would return unauthorized and the app should just redirect to the laravel login page. A new login would equal a new session token which would be passed back to the app via window.session
just like the access token is currently passed.
Two different methods of Auth means double the potential for bugs and security risks. For example if an account was compromised the attacker could log in and get the access token and access to the account forever.
The user would likely reset their password and then consider the account secure however this would not effect access tokens. I suspect the double system introduces more such vulnerabilities.
…On Mon, 23 Jan 2023, 15:32 Jan Misker, ***@***.***> wrote:
Indeed, basically there are 2 points of authorization: 1) onConnected, and
2) onChange (with a delay) to store the document back to the database. Both
via callbacks to this extension.
I guess the tricky part with using a session token is what happens when
the token expires. How to provide a new session token? But as said, I
didn't create this package, I hope the authors also respond.
—
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB6COEMLQMNTRK3SWT642FDWT2CATANCNFSM6AAAAAAUDU6UHQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I've managed to get this approach working for anyone interested. I believe it's significantly better than the access token system currently used because:
It does require a csrf token to be passed in place of the accessToken however, as websockets are vunerable to csrf attacks. My method is to add a middleware that simply moves the session cookie, and csrf token to the request headers before the request is seen by the other built-in middleware. The built-in middleware then handles the authentication, verification of csrf, and makes the authenticated user available via Kernel.php
ParseHocusRequest::class
routes/api.php
You also need to pass a csrf token to the hocuspocus provider, for example: In
|
Update Auth with Laravel is better achieved using the Hocuspocus server's built-in onAuthenticate hook. No custom middleware is needed:
Plus add the csrf token in Hocuspocus provider:
|
I wondered if there was a reason not to use the built-in session for authentication of requests rather than custom tokens. The session id could be sent with the request the same way the access token currently is, however it would provide a number of advantages over the current access token system:
The text was updated successfully, but these errors were encountered: