Skip to content

Commit b2cd556

Browse files
authored
Fix User API Key login (#6712)
When using the latest Bitwarden CLI and logging in using the API Key, it expects some extra fields, same as for normal login. This PR adds those fields and login is possible again via API Key. Fixes #6709 Signed-off-by: BlackDex <black.dex@gmail.com>
1 parent 4352fff commit b2cd556

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/api/identity.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,25 @@ async fn _user_api_key_login(
610610

611611
info!("User {} logged in successfully via API key. IP: {}", user.email, ip.ip);
612612

613+
let has_master_password = !user.password_hash.is_empty();
614+
let master_password_unlock = if has_master_password {
615+
json!({
616+
"Kdf": {
617+
"KdfType": user.client_kdf_type,
618+
"Iterations": user.client_kdf_iter,
619+
"Memory": user.client_kdf_memory,
620+
"Parallelism": user.client_kdf_parallelism
621+
},
622+
// This field is named inconsistently and will be removed and replaced by the "wrapped" variant in the apps.
623+
// https://github.com/bitwarden/android/blob/release/2025.12-rc41/network/src/main/kotlin/com/bitwarden/network/model/MasterPasswordUnlockDataJson.kt#L22-L26
624+
"MasterKeyEncryptedUserKey": user.akey,
625+
"MasterKeyWrappedUserKey": user.akey,
626+
"Salt": user.email
627+
})
628+
} else {
629+
Value::Null
630+
};
631+
613632
// Note: No refresh_token is returned. The CLI just repeats the
614633
// client_credentials login flow when the existing token expires.
615634
let result = json!({
@@ -625,6 +644,11 @@ async fn _user_api_key_login(
625644
"KdfParallelism": user.client_kdf_parallelism,
626645
"ResetMasterPassword": false, // TODO: according to official server seems something like: user.password_hash.is_empty(), but would need testing
627646
"scope": AuthMethod::UserApiKey.scope(),
647+
"UserDecryptionOptions": {
648+
"HasMasterPassword": has_master_password,
649+
"MasterPasswordUnlock": master_password_unlock,
650+
"Object": "userDecryptionOptions"
651+
},
628652
});
629653

630654
Ok(Json(result))

0 commit comments

Comments
 (0)