2

I am using the Dart server side Aqueduct framework. My program uses their OAuth 2.0 Bearer authorisation to secure certain routes. This works fine. However, I have a problem when I try to establish a websocket connection through a secure route. This is the code:

router
  .route("/connect")
  .pipe(new Authorizer(authServer));
  .listen((request) async {
    var userID = request.authorization.resourceOwnerIdentifier;
    var socket = await WebSocketTransformer.upgrade(request.innerRequest);
    socket.listen((event) => handleEvent(event, fromUserID: userID));

    connections[userID] = socket;

    return null;
  });

This code is taken directly from the Aqueduct website: https://aqueduct.io/docs/http/websockets/.

My question is, how do should the client look for this? Specifically, how do I set the authorisation in the HTTP header when establishing the websocket connection. I have tried lots of different things, including the following:

void connect()
{
    _address = "ws://$ip:$port/connect";
    _webSocket = new WebSocket(_address, {"Authorization":"Bearer ks123..."});
}

And:

void connect()
{
    _address = "ws://$ip:$port/connect&access_token=ks123...";
    _webSocket = new WebSocket(_address);
}

And:

void connect()
{
    _address = "ws://$ip:$port/connect&Authorization=Bearer ks123...";
    _webSocket = new WebSocket(_address);
}

And:

void connect()
{
    _address = "ws://$ip:$port/connect";
    _webSocket = new WebSocket(_address, ["Authorization Bearer ks123.."]);
}

Does anyone know how to solve this?

SSS
  • 761
  • 2
  • 9
  • 19

0 Answers0