Skip to content

Commit

Permalink
Improve config (stuartcryan#39)
Browse files Browse the repository at this point in the history
* Add keywords to config type

* Add describtion to readme on how to update the path + gif

* Fix totp message; hardcode osascript path; fix issue for login without 2fa

* Fix issue for login without 2fa

* Update version to 2.0.5
  • Loading branch information
blacs30 authored Aug 27, 2020
1 parent 0ef89ae commit 03afcef
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
- If running on macOS Catalina or later, you _**MUST**_ add Alfred to the list of security exceptions for running unsigned software. See [this guide](https://github.com/deanishe/awgo/wiki/Catalina) for instructions on how to do this.
- <sub>Yes, this sucks and is annoying, but there is unfortunately is no easy way around this. macOS requires a paying Developer account for proper app notarization. I'm afraid I'm not willing to pay a yearly subscription fee to Apple just so that this (free and open source) project doesn't pester macOS Gatekeeper.</sub>

## PATH configuration

In many cases the bw executable is located in a path outside of the default system PATH.<br>
Please configure the Alfred Worklow variables PATH accordingly.<br>
In a normal terminal type `which bw` and copy the dirname (everything except the "bw") into the PATH workflow variable.<br>
The best is to append it to the existing string and separate it by a colon (:)

![Workflow PATH config](./assets/workflow-path-config.gif)

## Usage
To use, activate Alfred and type `.bw` to trigger this workflow. From there:

Expand Down
Binary file modified assets/bitwarden-v2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/workflow-path-config.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions bitwarden.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func runUnlock() {

}

inputScriptPassword := fmt.Sprintf("osascript bitwarden-js-pw-promot.js Unlock %s password true", email)
inputScriptPassword := fmt.Sprintf("/usr/bin/osascript bitwarden-js-pw-promot.js Unlock %s password true", email)
message := "Failed to get Password to Unlock."
// user needs to input pasword
passwordReturn, err := runCmd(inputScriptPassword, message)
Expand Down Expand Up @@ -398,7 +398,7 @@ func runLogin() {
}
}

inputScriptPassword := fmt.Sprintf("osascript bitwarden-js-pw-promot.js Login %s password true", email)
inputScriptPassword := fmt.Sprintf("/usr/bin/osascript bitwarden-js-pw-promot.js Login %s password true", email)
message := "Failed to get Password to Login."
passwordReturn, err := runCmd(inputScriptPassword, message)
if err != nil {
Expand All @@ -416,7 +416,7 @@ func runLogin() {
args := fmt.Sprintf("%s login %s %s", conf.BwExec, email, password)
if sfa {
display2faMode := map2faMode(sfaMode)
inputScript2faCode := fmt.Sprintf("osascript bitwarden-js-pw-promot.js Login %s %s false", email, display2faMode)
inputScript2faCode := fmt.Sprintf("/usr/bin/osascript bitwarden-js-pw-promot.js Login %s %s false", email, display2faMode)
message := "Failed to get 2FA code to Login."
sfacodeReturn, err := runCmd(inputScript2faCode, message)
sfaCode := ""
Expand Down
11 changes: 8 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"github.com/blacs30/bitwarden-alfred-workflow/alfred"
"github.com/kelseyhightower/envconfig"
"os"
"strings"
"time"

Expand Down Expand Up @@ -40,9 +41,9 @@ type config struct {
// From workflow environment variables
AutoFetchIconCacheAge int `default:"1440" split_words:"true"`
AutoFetchIconMaxCacheAge time.Duration
BwconfKeyword string `split_words:"true"`
BwauthKeyword string `split_words:"true"`
BwKeyword string `split_words:"true"`
BwconfKeyword string
BwauthKeyword string
BwKeyword string
BwExec string `split_words:"true"`
CacheAge int `default:"1440" split_words:"true"`
Email string
Expand All @@ -57,6 +58,7 @@ type config struct {
Mod3 string `envconfig:"MODIFIER_3" default:"cmd"`
Mod4 string `envconfig:"MODIFIER_4" default:"cmd,alt,ctrl"`
OutputFolder string `default:"" split_words:"true"`
Path string
ReorderingDisabled bool `default:"true" split_words:"true"`
Server string `envconfig:"SERVER_URL" default:"https://bitwarden.com"`
Sfa bool `envconfig:"2FA_ENABLED" default:"true"`
Expand All @@ -83,6 +85,9 @@ func loadConfig() {
conf.AutoFetchIconMaxCacheAge = autoFetchIconCacheAgeDuration * time.Minute
syncCacheAgeDuration := time.Duration(conf.SyncCacheAge)
conf.SyncMaxCacheAge = syncCacheAgeDuration * time.Minute
conf.BwauthKeyword = os.Getenv("bwauth_keyword")
conf.BwconfKeyword = os.Getenv("bwconf_keyword")
conf.BwKeyword = os.Getenv("bw_keyword")
initModifiers()
}

Expand Down
1 change: 1 addition & 0 deletions items.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ func addItemsToWorkflow(item Item, autoFetchCache bool) {
Icon(iconUser)
if totp != "" {
it1.NewModifier(mod2[0:]...).Subtitle("Copy TOTP").
Var("notification", fmt.Sprintf("Copy TOTP for user:\n%s", item.Login.Username)).
Var("action", "-getitem").
Var("action2", "-totp").
Var("action3", fmt.Sprintf("-id %s", item.Id)).
Expand Down
3 changes: 3 additions & 0 deletions workflow/bitwarden-auth-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function run(arg) {
} else {
var totpInt = arg[2]
var totpStr = arg[3]
if(totpStr == null){
totpStr = " "
}

var text = `Login to Bitwarden for user ${email}.\nPlease enter your password:`
var response = app.displayDialog(text, {
Expand Down
2 changes: 1 addition & 1 deletion workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ Caching of the secret/item names (not the secret values itself) are cached so th
<string>SERVER_URL</string>
</array>
<key>version</key>
<string>2.0.4</string>
<string>2.0.5</string>
<key>webaddress</key>
<string>https://github.com/blacs30/bitwarden-alfred-workflow</string>
</dict>
Expand Down

0 comments on commit 03afcef

Please sign in to comment.