aboutsummaryrefslogtreecommitdiff
path: root/auth/auth.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-10-04 00:09:34 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-10-04 00:09:34 +0530
commit50f211800946318ff4e3c40c1fc497c149b0380d (patch)
treed4a8f15f05c1b21749593495c99437aad5385b04 /auth/auth.go
parent1b45e30a8f0cbeb8b28a1464dc4342bffa958627 (diff)
Use the macli.toml file to store and get login info automatically
Diffstat (limited to 'auth/auth.go')
-rw-r--r--auth/auth.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/auth/auth.go b/auth/auth.go
index 5a768ff..15ad854 100644
--- a/auth/auth.go
+++ b/auth/auth.go
@@ -26,6 +26,7 @@ import (
"errors"
"fmt"
"github.com/zalando/go-keyring"
+ "github.com/spf13/viper"
)
var serviceName string = "macli"
@@ -43,10 +44,16 @@ func init() {
// asks for all the details
func Login(tk, clientId string, storeClientId bool) {
- /* check if an auth token already exists
- * if there is an error with keyring, askClientId would handle it
- * can safely ignore error here */
- existingToken, _ := keyring.Get(serviceName, userName)
+ // check if an auth token already exists
+ var existingToken string
+ if NoSysKeyring {
+ existingToken = viper.GetString("auth.token")
+ } else {
+ /* if there is an error with keyring, askClientId would handle it
+ * can safely ignore error here */
+ existingToken, _ = keyring.Get(serviceName, userName)
+ }
+
if existingToken != "" {
if !confirmInput("Already logged in. Log in again? [Y/n] ", true) {
fmt.Println("Login process aborted")