Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[websocket] Support token authentication through header #4515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Dec 22, 2024

Closes #4490.

Browser clients do not have the ability to set an Authorization header programatically on websocket requests. All they have control over is the URL and the websocket subprotocols sent (see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)

This PR adds support for specifying a bearer token via a websocket subprotocol, with the format org.openhab.ws.accessToken.base64.<encoded-token>.

The browser must specify at least one other subprotocol since the server must echo a selected subprotocol back.
For this, org.openhab.ws.protocol.default is used.

<encoded-token> must be base64-encoded without padding, since bearer tokens can contain characters a websocket protocol may not (/ and =).

@florian-h05 florian-h05 force-pushed the websocket-auth-header branch from 19ec9f0 to 164291a Compare December 22, 2024 14:07
@florian-h05 florian-h05 marked this pull request as ready for review December 22, 2024 14:08
@florian-h05 florian-h05 requested a review from a team as a code owner December 22, 2024 14:08
@florian-h05
Copy link
Contributor Author

@ghys This was easier to implement than I expected 👍

@ghys
Copy link
Member

ghys commented Dec 22, 2024

@florian-h05 you're underestimating yourself ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing the access token in Sec-WebSocket-Protocol header to authorize WebSocket connections
2 participants