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

Allow setting basic auth credentials in websocket url #590

Merged
merged 6 commits into from
Feb 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/transports/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ impl WsServerTask {
resource
);
let mut client = Client::new(socket, host, &resource);
let maybe_encoded = url.password().map(|password| {
use headers::authorization::{Authorization, Credentials};
log::trace!("Basic auth username: {}", url.username());
log::trace!("Basic auth password: {}", password);
717a56e1 marked this conversation as resolved.
Show resolved Hide resolved
Authorization::basic(url.username(), password).0.encode().to_str().unwrap().as_bytes().to_owned()
717a56e1 marked this conversation as resolved.
Show resolved Hide resolved
});

let headers = if let Some(ref head) = maybe_encoded {
Some([soketto::handshake::client::Header {name: "Authorization",value: &head }])
717a56e1 marked this conversation as resolved.
Show resolved Hide resolved
} else { None };

if let Some(ref head) = headers {
client.set_headers(head);
}
let handshake = client.handshake();
let (sender, receiver) = match handshake.await? {
ServerResponse::Accepted { .. } => client.into_builder().finish(),
Expand Down