How can I send authorization header for OAuth2 in SSE in javascript? It seems like native JS EventSource does not support any headers to be sent when listening to SSE. Is there another library maybe that will allow me to do that? Does anyone have any idea how to do it?
To send a GET request with a Bearer Token authorization header, you need to make an HTTP GET request and provide your Bearer Token with the Authorization: Bearer {token} HTTP header.
To send a request with the Bearer Token authorization header, you need to make an HTTP request and provide your Bearer Token with the "Authorization: Bearer {token}" header. A Bearer Token is a cryptic string typically generated by the server in response to a login request.
SSE is designed to use the JavaScript EventSource API in order to subscribe to a stream of data in any popular browser. Through this interface a client requests a particular URL in order to receive an event stream. SSE is commonly used to send message updates or continuous data streams to a browser client.
The SSE standard does not support sending headers (or POST data). Only GET data and cookies. Your choices boil down to:
EventSource
request.XMLHttpRequest2
, i.e. comet/longpoll techniques.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With