问题
My API Manager tool mandates that i should pass the Authorization Bearer access token with the websocket invocation call. They are providing samples of java code where they do that.
The bearer token is set like ("Authorization", "Bearer e2238f3a-e43c-3f54-a05a-dd2e4bd4631f") .How can i do that in javascript?
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
final WebSocketClientHandler handler = new WebSocketClientHandler(
WebSocketClientHandshakerFactory
.newHandshaker(uri, WebSocketVersion.V13, null,
false, new DefaultHttpHeaders()
.add("Authorization", "Bearer e2238f3a-e43c-3f54-a05a-dd2e4bd4631f")));
This is how they do it in java Is there a way like this to do it from my java script[Angular2] web application? How can i pass this from UI? Any Websocket bases testing tool can emulate this?
回答1:
I found this answer here: https://stackoverflow.com/a/26123316/1715121
"It is impossible for now to use the Authentication header, because of the design of Javascript WebSocket API. More information can be found in this thread: HTTP headers in Websockets client API
However, Bearer authentication type allows a request parameter named "access_token": http://self-issued.info/docs/draft-ietf-oauth-v2-bearer.html#query-param This method is compatible with websocket connection."
来源:https://stackoverflow.com/questions/47625452/how-to-pass-authorization-bearer-access-token-in-websocket-javascript-client