diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-15 15:00:33 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-15 15:00:33 +0530 |
commit | 83e1ce2508ea035fb299a88fe89e82f34e609499 (patch) | |
tree | 23acfe56acd7175d3430a2375946d96227bef168 /auth/auth.go | |
parent | 7d1c4adb6496ff9a2167f3e83b34fd5952068545 (diff) |
pushing incomplete login functionality
Diffstat (limited to 'auth/auth.go')
-rw-r--r-- | auth/auth.go | 29 |
1 files changed, 13 insertions, 16 deletions
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() } |