2

I am using a web-socket based implementation in one of my web app. I already have a JWT generated by Cognito. I want to pass the same token during initializing the connection to socket. I went through this link which talks about it but exact details are not specified.

I am using Angular on my client side and using RxJs websocket API to make a connection as below:

private subject = webSocket('wss://xxxxxx.execute-api.ap-south-1.amazonaws.com/production');


connectToWS() {
    this.subject.subscribe(
      msg => console.log('message received: ' + JSON.stringify(msg)), // Called whenever there is a message from the server.
      err => console.log(err), // Called if at any point WebSocket API signals some kind of error.
      () => console.log('complete') // Called when connection is closed (for whatever reason).
    );
  }

I think the $connect route is automatically called when subscribing to the subject. How can I pass my token to it ? Is there any way to supply headers in wss similar to https ?

Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82
  • Please have a look at the answers here: https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api – daflodedeing May 30 '22 at 09:02

0 Answers0