如何在websocket javascript客户端中传递授权承载访问令牌 [英] how to pass Authorization Bearer access token in websocket javascript client
问题描述
我的API管理器工具要求我应通过websocket调用调用传递授权承载访问令牌.他们提供了Java代码示例.
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.
不记名令牌设置为(授权","bearer e2238f3a-e43c-3f54-a05a-dd2e4bd4631f").如何在javascript中做到这一点?
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")));
这是他们在Java中的操作方式从我的Java脚本[Angular2] Web应用程序中可以做到这一点吗?我如何通过UI传递此信息?任何基于Websocket的测试工具都可以模拟吗?
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?
推荐答案
我在这里找到了这个答案: https://stackoverflow.com/a/26123316/1715121
由于Javascript WebSocket API的设计,目前无法使用Authentication标头.在此线程中可以找到更多信息: Websockets客户端API中的HTTP标头
"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
但是,承载身份验证类型允许使用名为"access_token"的请求参数:
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."
这篇关于如何在websocket javascript客户端中传递授权承载访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!