From 775b8a4a1c8b73a38ecc7e75495361a6e9d74be1 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 20 May 2024 18:44:28 +0530 Subject: using the maltoken package to log in now --- auth/auth.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'auth/auth.go') diff --git a/auth/auth.go b/auth/auth.go index b75c392..9374c72 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -1,6 +1,6 @@ /* macli - Unofficial CLI-Based MyAnimeList Client -Copyright © 2022 Vidhu Kant Sharma +Copyright © 2022-2024 Vidhu Kant Sharma This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ along with this program. If not, see . package auth import ( + mt "vidhukant.com/maltoken" "errors" "fmt" "github.com/spf13/viper" @@ -42,6 +43,10 @@ func init() { os.Exit(1) } userName = currentUser.Username + + mt.SuccessHTML = fmt.Sprintf(HTMLTemplate, "Login successful.", "Thanks for using macli. You may close this tab now.") + mt.BadRequestHTML = fmt.Sprintf(HTMLTemplate, "Invalid request.", "Required query parameters are missing.") + mt.ErrHTML = fmt.Sprintf(HTMLTemplate, "An error occoured.", "%s") } // asks for all the details @@ -83,15 +88,16 @@ func Login(tk, clientId string, storeClientId bool) { return } - challenge := codeChallenge() - link := generateLink(clientId, challenge) + challenge, link := mt.GetChallengeLink(clientId) openInBrowser(link) - listen(clientId, challenge) -} + res, err := mt.Listen(clientId, challenge, 8000) + if err != nil { + fmt.Printf("\x1b[1;31mAn error occoured:\x1b[0m %s\nExiting...\n", err.Error()) + 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 + setToken(res["access_token"].(string)) } func openInBrowser(url string) { @@ -119,8 +125,6 @@ func openInBrowser(url string) { func Logout() { existingToken, _ := keyring.Get(serviceName, userName) deleteToken() - deleteExpiresIn() - deleteRefreshToken() if existingToken != "" { fmt.Println("Deleted user credentials.") } -- cgit v1.2.3