added ability to delete entries. Added MAL RefreshToken Function
This commit is contained in:
@ -224,6 +224,77 @@ func getMyAnimeListAuthorizationToken(content string, verifier *CodeVerifier) My
|
||||
return post
|
||||
}
|
||||
|
||||
func refreshMyAnimeListAuthorizationToken() {
|
||||
dataForURLs := struct {
|
||||
GrantType string `json:"grant_type"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
RedirectURI string `json:"redirect_uri"`
|
||||
}{
|
||||
GrantType: "refresh_token",
|
||||
RefreshToken: myAnimeListJwt.RefreshToken,
|
||||
ClientID: Environment.MAL_CLIENT_ID,
|
||||
ClientSecret: Environment.MAL_CLIENT_SECRET,
|
||||
RedirectURI: Environment.MAL_CALLBACK_URI,
|
||||
}
|
||||
|
||||
data := url.Values{}
|
||||
data.Set("grant_type", dataForURLs.GrantType)
|
||||
data.Set("refresh_token", dataForURLs.RefreshToken)
|
||||
data.Set("client_id", dataForURLs.ClientID)
|
||||
data.Set("client_secret", dataForURLs.ClientSecret)
|
||||
data.Set("redirect_uri", dataForURLs.RedirectURI)
|
||||
|
||||
response, err := http.NewRequest("POST", "https://myanimelist.net/v1/oauth2/token", strings.NewReader(data.Encode()))
|
||||
if err != nil {
|
||||
log.Printf("Failed at response, %s\n", err)
|
||||
}
|
||||
response.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
client := &http.Client{}
|
||||
res, reserr := client.Do(response)
|
||||
if reserr != nil {
|
||||
log.Printf("Failed at res, %s\n", err)
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
returnedBody, err := io.ReadAll(res.Body)
|
||||
|
||||
err = json.Unmarshal(returnedBody, &myAnimeListJwt)
|
||||
if err != nil {
|
||||
log.Printf("Failed at unmarshal, %s\n", err)
|
||||
}
|
||||
|
||||
_ = myAnimeListRing.Set(keyring.Item{
|
||||
Key: "MyAnimeListTokenType",
|
||||
Data: []byte(myAnimeListJwt.TokenType),
|
||||
})
|
||||
_ = myAnimeListRing.Set(keyring.Item{
|
||||
Key: "MyAnimeListExpiresIn",
|
||||
Data: []byte(strconv.Itoa(myAnimeListJwt.ExpiresIn)),
|
||||
})
|
||||
_ = myAnimeListRing.Set(keyring.Item{
|
||||
Key: "MyAnimeListAccessToken",
|
||||
Data: []byte(myAnimeListJwt.AccessToken),
|
||||
})
|
||||
_ = myAnimeListRing.Set(keyring.Item{
|
||||
Key: "MyAnimeListRefreshToken",
|
||||
Data: []byte(myAnimeListJwt.RefreshToken),
|
||||
})
|
||||
_, err = runtime.MessageDialog(*wailsContext, runtime.MessageDialogOptions{
|
||||
Title: "MyAnimeList Authorization",
|
||||
Message: "It is now safe to close your browser tab",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser {
|
||||
a.MyAnimeListLogin()
|
||||
|
||||
|
Reference in New Issue
Block a user