Skip to content

Commit fc1593e

Browse files
committed
Add apikey based login strategy
1 parent 56581fb commit fc1593e

6 files changed

Lines changed: 401 additions & 93 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ configuration options:
7373

7474
* `email`: The email address to use as the account name when logging into the
7575
Bitwarden server. Required.
76+
* `client_id`: Client ID part of the API key. Defaults to regular login process if unset.
7677
* `sso_id`: The SSO organization ID. Defaults to regular login process if unset.
7778
* `base_url`: The URL of the Bitwarden server to use. Defaults to the official
7879
server at `https://api.bitwarden.com/` if unset.
@@ -102,6 +103,18 @@ between by using the `RBW_PROFILE` environment variable. Setting it to a name
102103
switch between several different vaults - each will use its own separate
103104
configuration, local vault, and agent.
104105

106+
### Auth methods
107+
108+
Currently `rbw` supports three login strategies, listed by order of priority:
109+
1. `apikey`, requires you to provide `client_id` and `client_secret`. Will be enabled
110+
when a `client_id` value is set in the config file
111+
2. `SSO` (Enterprise Single Sign-On). Will be enabled when a `sso_id` value is set in
112+
the config file. (Note: due to the current implementation, if your account is secured with 2FA
113+
you'll be required to go through the browser flow twice. You'll be prompted for the 2FA code
114+
after the first run)
115+
3. `email&password`, regular auth method, uses the same credentials as Bitwarden's Web Vault.
116+
That's most likely what you want to use
117+
105118
## Usage
106119

107120
Commands can generally be used directly, and will handle logging in or

src/actions.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ pub async fn register(
77
let (client, config) = api_client_async().await?;
88

99
client
10-
.register(email, &crate::config::device_id(&config).await?, &apikey)
10+
.register(
11+
email,
12+
&crate::config::device_id_async(&config).await?,
13+
&apikey,
14+
)
1115
.await?;
1216

1317
Ok(())
1418
}
1519

1620
pub async fn login(
1721
email: &str,
22+
apikey: Option<crate::locked::ApiKey>,
1823
password: crate::locked::Password,
1924
two_factor_token: Option<&str>,
2025
two_factor_provider: Option<crate::api::TwoFactorProviderType>,
@@ -42,9 +47,10 @@ pub async fn login(
4247
let (access_token, refresh_token, protected_key) = client
4348
.login(
4449
email,
50+
apikey.as_ref(),
4551
config.sso_id.as_deref(),
46-
&crate::config::device_id(&config).await?,
47-
&identity.master_password_hash,
52+
&crate::config::device_id_async(&config).await?,
53+
Some(&identity.master_password_hash),
4854
two_factor_token,
4955
two_factor_provider,
5056
)

0 commit comments

Comments
 (0)