tribally task verify
This commit is contained in:
@@ -46,3 +46,44 @@ func BindTribally(apiKey, userId string) (string, error) {
|
||||
}
|
||||
return result.Data.AuthURL, nil
|
||||
}
|
||||
|
||||
func VerifyTribally(token string) error {
|
||||
url := "https://api.tribally.games/member/me"
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result := struct {
|
||||
Error string `json:"error"`
|
||||
Code string `json:"code"`
|
||||
Data struct {
|
||||
UserID string `json:"userId"`
|
||||
ScreenName string `json:"screenName"`
|
||||
Slug string `json:"slug"`
|
||||
HasBattlePass bool `json:"hasBattlePass"`
|
||||
ProfileImage string `json:"profileImage"`
|
||||
} `json:"data"`
|
||||
}{}
|
||||
err = json.Unmarshal(body, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.Error != "" {
|
||||
return fmt.Errorf("error: %s, code: %s", result.Error, result.Code)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user