Comments (4)
Can you share the source code.
Thanks
from signalr_core.
@motasemloubani91
This is how it's supposed to work. The very first request after establishing a connection sends an initial http-request asking to upgrade the connection to websockets. Since it's an http-request, the middleware pipeline on the server runs and authenticates the request. Later messages on the same connection are part of the very same http-request, so no token is sent and no middleware runs, the messages go straight to the hub dispatcher on the server.
from signalr_core.
@rho-cassiopeiae @mohachouch In my case. the client implementation is sending two request. The first one with the token (a regular http-request) and the second one a http request with the mentioned Upgrade header (to websockets), but this request doesn't have the Authorization header. So it can't go through the auth / authorization pipeline.
This is the first request headers read by the server:
{"Host":["localhost:7180"],"User-Agent":["Dart/3.1 (dart:io)"],"Accept-Encoding":["gzip"],"Authorization":["<The token>"],"Content-Type":["text/plain;charset=UTF-8"],"Content-Length":["0"],"X-Requested-With":["FlutterHttpClient"]}
The second request:
{"Connection":["Upgrade"],"Host":["localhost:7180"],"User-Agent":["Dart/3.1 (dart:io)"],"Accept-Encoding":["gzip"],"Cache-Control":["no-cache"],"Upgrade":["websocket"],"Sec-WebSocket-Version":["13"],"Sec-WebSocket-Extensions":["permessage-deflate; client_max_window_bits"],"Sec-WebSocket-Key":["hpOTyivyudEzVXj7ZTCVGw=="]}
This is the relevant part of the code:
start() async {
var token = await firebaseAuth.currentUser!.getIdToken();
var httpConnectionOptions = HttpConnectionOptions(
accessTokenFactory: () => Future.delayed(Duration.zero, () => token!));
try {
_hubConnection = HubConnectionBuilder()
.withUrl(
"${await _settingsRepository.baseApiUrl(FlavorSingleton.flavor)}/hub/position-hub",
httpConnectionOptions)
.build();
if (_hubConnection.state != HubConnectionState.connected) {
await _hubConnection.start();
print(_hubConnection.connectionId);
_hubConnection.on("updatePositionToClient", (arguments) {});
}
from signalr_core.
As a hacky workaround I've added an Authorization header to the ws request in web_socket_channel_io.dart
var request = Request('GET', wsUri)
..headers.addAll({
'Connection': 'Upgrade',
'Authorization': 'Bearer $token',
'Upgrade': 'websocket',
'Sec-WebSocket-Key': nonce,
'Cache-Control': 'no-cache',
'Sec-WebSocket-Version': '13',
});
from signalr_core.
Related Issues (20)
- Upgrade http dependency HOT 5
- How to create builder with Header?
- Exception: The underlying connection was closed before the hub handshake could complete.
- BadState: Future already completed after calling _stopConnection
- signalr_core 1.1.1 depends on http ^0.13.0 HOT 2
- InvalidOperationException: Sequence contains no matching element HOT 1
- Unhandled Exception: Exception: HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) was called while the connection is still in the connecting state. HOT 1
- Firebase Hosting Connection failed (Exception: The underlying connection was closed before the hub handshake could complete..toString()) HOT 3
- How to add proxy to HubConnectionBuilder?
- Retry lost connection forever?
- Server timeout after 30 seconds with long polling transport
- Stop method is not working
- Problem with HTTPS url HOT 4
- Please make this change in your code HOT 2
- Hubconnection.stop() take too long time
- Run signalR in background native service (Java et Kt)
- What is the proper way to subscribe on the events in SignalR?
- The underlying connection was closed before the hub handshake could complete. HOT 1
- Future Plans HOT 8
- JavaScript error on laptop sleep only in release web build HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from signalr_core.