我試圖讓從前端至後端vertx一個sock.js連接。Vertx SockJs Eventbus認證
我最初的嘗試是這樣的:
let token = '<the token>';
let data = {'Authorization' : 'Bearer ' + token};
let eb = new EventBus("http://localhost:8080/eventbus");
eb.onopen = function() {
eb.registerHandler('notifications', data, (err, msg) => {
// handle the response
});
}
這不工作,因爲我需要發送的EventBus創建權威性的數據,即使官方sock.js文檔指出,這是不支持的。顯然現在發送new EventBus("http://localhost:9090/eventbus", data)
也不起作用。
https://github.com/sockjs/sockjs-node#authorisation
我這個後臺處理程序:
final BridgeOptions bridgeOptions = new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddress("notifications"))
final SockJSHandler sockJSHandler = SockJSHandler.create(vertx).bridge(bridgeOptions, event -> {
event.complete(true);
});
router.route("/eventbus/*").handler(ctx -> {
String token = ctx.request().getHeader("Authorization"); // null
});
router.route("/eventbus/*").handler(sockJSHandler);
無論我試過的頭字段Authroization
總是空。
什麼是認證sock.js連接和註冊中vertx的eventbus要求的標準呢?
您是否檢查過Vert.x Web文檔的[要求授權消息](http://vertx.io/docs/vertx-web/java/#_requiring_authorisation_for_messages)部分? – tsegismont
是的,我讀過了整個vertx文檔 – Markus
確定。我問,因爲您的代碼片段看起來不像您使用Vert.x Web授權功能。 – tsegismont