From 83e1ce2508ea035fb299a88fe89e82f34e609499 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 15 Jun 2022 15:00:33 +0530 Subject: pushing incomplete login functionality --- auth/auth.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'auth/auth.go') diff --git a/auth/auth.go b/auth/auth.go index c3b2cfd..e75d228 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -22,7 +22,6 @@ import ( "os" "os/user" "fmt" - "github.com/zalando/go-keyring" ) var serviceName string = "macli" @@ -38,22 +37,20 @@ func init() { userName = currentUser.Username } -func Login(secret string) { - err := keyring.Set(serviceName, userName, secret) - if err != nil { - fmt.Println("Error while writing access token to keychain", err) - os.Exit(1) - } +// asks for all the details +func Login() { + clientId := askClientId() + challenge := codeChallenge() + link := generateLink(clientId, challenge) + fmt.Println("Please open this link in the browser:") + fmt.Println(link) } -func GetToken() string { - // get mal secret from keyring - secret, err := keyring.Get(serviceName, userName) - if err != nil { - fmt.Println("\x1b[31mError while reading access token from keychain:", err.Error(), "\x1b[0m") - fmt.Println("Run `macli login` first to authenticate with your MyAnimeList API Token") - os.Exit(1) - } +func generateLink(clientId, challenge string) string { + return "https://myanimelist.net/v1/oauth2/authorize?response_type=code&client_id=" + clientId + "&code_challenge=" + challenge +} - return secret +func Logout() { + deleteClientId() + deleteToken() } -- cgit v1.2.3