Save the entire token, not just the ID (#211)

This allows us to use the token's scope to set the default scope for an
action in the client instead of relying on env vars.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-07-22 15:02:58 -04:00
1 parent 995b76bbc5
commit 2bbc1163c4
2 files changed
+30 -6

No files matched your search

@@ -1,6 +1,8 @@
package authenticate
import (
"encoding/base64"
"encoding/json"
"fmt"
"os"
"strings"
@@ -153,7 +155,12 @@ func (c *PasswordCommand) Run(args []string) int {
tokenName = c.Command.FlagTokenName
}
if tokenName != "none" {
if err := keyring.Set("HashiCorp Watchtower Auth Token", tokenName, result.Token); err != nil {
marshaled, err := json.Marshal(result)
if err != nil {
c.UI.Error(fmt.Sprintf("Error marshaling auth token to save to system credential store: %s", err))
return 1
}
if err := keyring.Set("HashiCorp Watchtower Auth Token", tokenName, base64.RawStdEncoding.EncodeToString(marshaled)); err != nil {
c.UI.Error(fmt.Sprintf("Error saving auth token to system credential store: %s", err))
return 1
}