Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 how to auth websocket or EventSource ?

views
     
TS15cm
post Mar 14 2025, 05:18 PM, updated 10 months ago

Casual
***
Junior Member
423 posts

Joined: Apr 2022
Websocket and EventSource cannot carry custom header on browser. well then how can i have it carry my token to be authed?

the only other way i can think of is to carry it via url, which is not secure
ragk
post Mar 14 2025, 05:26 PM

BooBoo~
*******
Senior Member
2,354 posts

Joined: Apr 2009


U dun have to carry ur token on every request, u authenticate it when u establish the socket
https://ably.com/blog/websocket-authentication
TS15cm
post Mar 14 2025, 05:43 PM

Casual
***
Junior Member
423 posts

Joined: Apr 2022
QUOTE(ragk @ Mar 14 2025, 05:26 PM)
U dun have to carry ur token on every request, u authenticate it when u establish the socket
https://ably.com/blog/websocket-authentication
*
but if someone figure out the endpoint for socket they can try to connect to the socket directly?

edit: oh ok i realise what u meant u cant add custom header during the handshake as well right?


This post has been edited by 15cm: Mar 14 2025, 05:47 PM
ragk
post Mar 14 2025, 05:51 PM

BooBoo~
*******
Senior Member
2,354 posts

Joined: Apr 2009


QUOTE(15cm @ Mar 14 2025, 05:43 PM)
but if someone figure out the endpoint for socket they can try to connect to the socket directly?

edit: oh ok i realise what u meant u cant add custom header during the handshake as well right?
*
The link got the example of submitting token during handshake too
QUOTE
const ws  = new WebSocket(
  "wss://example.com/path",
  ["Authorization", "your_token_here"]
)


TS15cm
post Mar 14 2025, 05:53 PM

Casual
***
Junior Member
423 posts

Joined: Apr 2022
QUOTE(ragk @ Mar 14 2025, 05:51 PM)
The link got the example of submitting token during handshake too
*
hmm i thought its not possible lol

let me try this later
ragk
post Mar 14 2025, 05:54 PM

BooBoo~
*******
Senior Member
2,354 posts

Joined: Apr 2009


QUOTE(15cm @ Mar 14 2025, 05:53 PM)
hmm  i thought its not possible lol

let me try this later
*
Please read the pros and cons too, the post discussed pros and cons of all methods

 

Change to:
| Lo-Fi Version
0.0132sec    0.73    5 queries    GZIP Disabled
Time is now: 24th December 2025 - 08:26 AM