aboutsummaryrefslogtreecommitdiff
path: root/auth/auth.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-08-16 13:35:50 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-08-16 13:35:50 +0530
commit5686c94f5fc24f7ec6927ab4b80b30d8644fba8f (patch)
treee21bc24ef579e034a66cb688469d03d61d16a7ba /auth/auth.go
parentd7a820b1115a3765daecf05b13a8caa94f432e85 (diff)
reading Client ID and/or Auth Token from flags in login command
Diffstat (limited to 'auth/auth.go')
-rw-r--r--auth/auth.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/auth/auth.go b/auth/auth.go
index 5955073..be17271 100644
--- a/auth/auth.go
+++ b/auth/auth.go
@@ -28,7 +28,7 @@ import (
"github.com/zalando/go-keyring"
)
-var serviceName string = "macli"
+var serviceName string = "macliTesting" // "macli"
var userName string
func init() {
@@ -42,7 +42,7 @@ func init() {
}
// asks for all the details
-func Login() {
+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 */
@@ -54,7 +54,22 @@ func Login() {
}
}
- clientId := askClientId()
+ if clientId == "" {
+ clientId = askClientId(storeClientId)
+ } else {
+ validateClientId(clientId)
+ if storeClientId {
+ setClientId(clientId)
+ }
+ }
+
+ if tk != "" {
+ setToken(tk)
+ fmt.Println("\x1b[32mYou have successfully logged into macli.\x1b[0m")
+ fmt.Println("\x1b[32mYou can close the web browser tab now.\x1b[0m")
+ return
+ }
+
challenge := codeChallenge()
link := generateLink(clientId, challenge)