From 5686c94f5fc24f7ec6927ab4b80b30d8644fba8f Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 16 Aug 2022 13:35:50 +0530 Subject: reading Client ID and/or Auth Token from flags in login command --- auth/auth.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'auth/auth.go') 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) -- cgit v1.2.3