diff options
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() } |