I am trying to hit a private WebSocket server through javascript client code. This WebSocket is hosted on GCP as a private cloud-run service. Can you please help me to hit this WebSocket by passing the "Authorization" token as part of the header?
I am currently calling the WebSocket using this approach
const socket = new WebSocket('wss://web-adaptor-service-lz7ymxgtha-ue.a.run.app');
I just need to pass the Authorization bearer token along wiht this url. Please help me with this.
NOTE : I am able to hit the same websocket by passing the required header using postman. I am attaching that snippet herewith for your reference. Please check it out. I just want to achieve the same using javascript client code
Thanks in advance!!!
I tried to connect the websocket server from javascript client code by passing the headers in the below mentioned ways but all ultimately failed. I am everytime getting 403 error during doing this connectivity.
const websocketUrl = 'wss://web-adaptor-service-lz7ymxgtha-ue.a.run.app';
const gcp_auth_token = 'eyJhbGciOiJSU**************************';
1.1 socket = new WebSocket(websocketUrl + '?Authorization=Bearer ' + gcp_auth_token);
1.2 socket = new WebSocket(websocketUrl + '?Origin=' + gcp_auth_token);
1.3 socket = new webSocket(websocketUrl, null, {
headers: {
['Authorization']: 'Bearer ' + gcp_auth_token
}
});
1.4 socket = new WebSocket(websocketUrl + '?access_token=' + gcp_auth_token);
1.5 socket = new WebSocket("wss://<gcp_auth_token>@<websocketUrl>");
1.6 socket = new WebSocket(websocketUrl , ["access_token", `${gcp_auth_token}']);
1.7 socket = new WebSocket(websocketUrl , [
"base64url.bearer.authorization.k8s.io.<base64encodedtoken>",
"base64.binary.k8s.io"
]); //this format is give in this link => https://github.com/kubernetes/kubernetes/pull/47740 which is also failing