Skip to content

Commit a27d468

Browse files
authored
WebSocket API: Add sending access token through sub-protocols header (#2442)
* WebSocket API: Add sending access token through sub-protocols header Refs openhab/openhab-core#4515. Signed-off-by: Florian Hotze <[email protected]> * Update configuration/websocket.md Signed-off-by: Florian Hotze <[email protected]> --------- Signed-off-by: Florian Hotze <[email protected]> Signed-off-by: Florian Hotze <[email protected]>
1 parent 44afc86 commit a27d468

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

configuration/websocket.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ All messages on the WebSocket connection are JSON encoded text-messages.
1212
## Establishing a connection
1313

1414
WebSockets are available on the same ports as the REST API, usually port 8080 for unsecured (ws-protocol) and port 8443 for secured (wss-protocol) connections.
15-
The connection is established by connecting to `ws[s]://{URL}:{PORT}/ws?accessToken={TOKEN}`.
15+
The connection is established by connecting to `ws[s]://{URL}:{PORT}/ws`.
1616

17-
To prevent unauthorized use of the connection an `accessToken` has to be sent with the initial request.
18-
{TOKEN} can be one of these two:
17+
To prevent unauthorized use of the connection, an access token has to be sent with the initial request.
18+
There are two options to send the access token:
19+
20+
1. Through the `Sec-WebSocket-Protocol` header:<br>
21+
As browsers cannot add `Authorization` headers to WebSocket requests but can specify WebSocket sub-protocols to send with the request.<br>
22+
You need to set the `org.openhab.ws.protocol.default` and `org.openhab.ws.accessToken.base64.${BASE64_TOKEN}` sub-protocols, where `${BASE64_TOKEN}` is the Base64 encoded `${TOKEN}` without `=` padding.
23+
The server will respond with the `org.openhab.ws.protocol.default` sub-protocol (as browsers require the server to select one of the provided sub-protocols).<br>
24+
25+
1. Through the `accessToken` query parameter: `ws[s]://{URL}:{PORT}/ws?accessToken={TOKEN}`.
26+
27+
`${TOKEN}` can be one of these two:
1928

2029
1. An API token: `oh.ohwstest.tz1IDPniKLxc0VU4t9tz4GiAiKmc0ZDdMKxhlD5tfviQStM4oNsywrcrUTktPbBE9YQ3wnMBrCqVEIhg7Q`
2130

22-
1. Basic Auth with base64 encoded {USER}:{PASSWORD}: `dXNlcjpwYXNzd29yZA==`
31+
1. Basic Auth with base64 encoded `{USER}:{PASSWORD}`: `dXNlcjpwYXNzd29yZA==`
2332

2433
## Using the WebSocket connection
2534

0 commit comments

Comments
 (0)