Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
fix the totp fallback via bw cli (#172)
Browse files Browse the repository at this point in the history
* fix the totp fallback via bw cli

* remove unused code for totp

* don't check for attachment; otherwise never entring jsonPath checks
  • Loading branch information
blacs30 authored Aug 31, 2023
1 parent 6d957d0 commit a9d20b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/bitwarden.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ func runGetItem() {
receivedItem = decryptedString
}
if bwData.UserId == "" || isDecryptSecretFromJsonFailed || attachment != "" {
log.Println("Falling back to Bitwarden CLI to get item.")

// Run the Bitwarden CLI to get the secret
// Use it also for getting attachments
if attachment != "" {
Expand All @@ -297,8 +299,10 @@ func runGetItem() {
message := "Failed to get Bitwarden item."
args := fmt.Sprintf("%s get item %s --pretty --session %s", conf.BwExec, id, token)
if totp {
log.Println("Trying to get totp via Bitwarden cli")
args = fmt.Sprintf("%s get totp %s --session %s", conf.BwExec, id, token)
} else if attachment != "" {
log.Println("Trying to get attachment via Bitwarden cli")
args = fmt.Sprintf("%s get attachment %s --itemid %s --output %s --session %s --raw", conf.BwExec, attachment, id, conf.OutputFolder, token)
}

Expand All @@ -314,8 +318,12 @@ func runGetItem() {
return
}

receivedItem = ""
if jsonPath != "" {
if totp {
} else {
receivedItem = ""
}
if jsonPath != "" && !totp {
log.Println("Sent jsonPath is", jsonPath)
// jsonpath operation to get only required part of the item
singleString := strings.Join(result, " ")
var item interface{}
Expand Down
2 changes: 1 addition & 1 deletion workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ Caching of the secret/item names (not the secret values itself) are cached so th
<string>true</string>
</dict>
<key>version</key>
<string>3.0.0</string>
<string>3.0.1</string>
<key>webaddress</key>
<string>https://github.com/blacs30/bitwarden-alfred-workflow</string>
</dict>
Expand Down

0 comments on commit a9d20b5

Please sign in to comment.