aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-07-18 03:39:59 -0400
committerJesse Luehrs <doy@tozt.net>2023-07-18 03:41:17 -0400
commitd2a97be689b034ed056f3ba41a9775635872a073 (patch)
treeb3b7cdba70d065f78465690b9e6e014f7c085e5f
parentcf75da99817cadba82299ef3d106da5308433486 (diff)
downloadrbw-d2a97be689b034ed056f3ba41a9775635872a073.tar.gz
rbw-d2a97be689b034ed056f3ba41a9775635872a073.zip
fix websockets for self-hosted bitwarden
-rw-r--r--README.md3
-rw-r--r--src/bin/rbw-agent/actions.rs13
-rw-r--r--src/config.rs12
3 files changed, 21 insertions, 7 deletions
diff --git a/README.md b/README.md
index 7ea61ee..f327ade 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,9 @@ configuration options:
* `identity_url`: The URL of the Bitwarden identity server to use. If unset,
will use the `/identity` path on the configured `base_url`, or
`https://identity.bitwarden.com/` if no `base_url` is set.
+* `notifications_url`: The URL of the Bitwarden notifications server to use.
+ If unset, will use the `/notifications` path on the configured `base_url`,
+ or `https://notifications.bitwarden.com/` if no `base_url` is set.
* `lock_timeout`: The number of seconds to keep the master keys in memory for
before requiring the password to be entered again. Defaults to `3600` (one
hour).
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index c44f601..6291680 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -697,13 +697,12 @@ pub async fn subscribe_to_notifications(
let access_token =
db.access_token.context("Error getting access token")?;
- let mut websocket_url = config
- .base_url
- .clone()
- .expect("config is missing base url")
- .replace("https://", "wss://")
- + "/notifications/hub?access_token=";
- websocket_url.push_str(&access_token);
+ let websocket_url = format!(
+ "{}/hub?access_token={}",
+ config.notifications_url(),
+ access_token
+ )
+ .replace("https://", "wss://");
let mut state = state.lock().await;
let err = state
diff --git a/src/config.rs b/src/config.rs
index d70a21b..03a9641 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -8,6 +8,7 @@ pub struct Config {
pub email: Option<String>,
pub base_url: Option<String>,
pub identity_url: Option<String>,
+ pub notifications_url: Option<String>,
#[serde(default = "default_lock_timeout")]
pub lock_timeout: u64,
#[serde(default = "default_sync_interval")]
@@ -26,6 +27,7 @@ impl Default for Config {
email: None,
base_url: None,
identity_url: None,
+ notifications_url: None,
lock_timeout: default_lock_timeout(),
sync_interval: default_sync_interval(),
pinentry: default_pinentry(),
@@ -159,6 +161,16 @@ impl Config {
}
#[must_use]
+ pub fn notifications_url(&self) -> String {
+ self.notifications_url.clone().unwrap_or_else(|| {
+ self.base_url.clone().map_or_else(
+ || "https://notifications.bitwarden.com".to_string(),
+ |url| format!("{}/notifications", url.trim_end_matches('/')),
+ )
+ })
+ }
+
+ #[must_use]
pub fn client_cert_path(&self) -> Option<&std::path::Path> {
self.client_cert_path.as_deref()
}