Reputation: 100
I want to pass authorization headers from js client to the python code during the socketio connection. I am using SocketIo-client v.4
and flask-socketio v.5
.
socketio client connection:
socket = io(`${config.apiUrl}/friendship`, {
autoConnect: true,
transportOptions: {
polling: {
extraHeaders: {"Authorization": "Bearer abc"},
},
}
}),
sample server python code:
class FriendshipNamespace(Namespace):
def on_connect(self):
print(request.headers) # no Authorization key
print(request.headers.get('Authorization')) # None
# join_room(self.room)
But I don't know why my backend doesn't receive this extraHeaders
. What is the correct way to send the access token to the server?
Tell me if you need some additional info. Would be grateful for any help, thank you😄.
Upvotes: 0
Views: 917
Reputation: 67479
You are passing options in a format that was used in an older version of the socket.io client.
Example from the documentation:
import { io } from "socket.io-client";
const socket = io({
extraHeaders: {
"my-custom-header": "1234"
}
});
See the current documentation for the extraHeaders option.
Upvotes: 0