Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Martyn | f7b047f8e3 | |
Martyn | 7735ca7a27 | |
Martyn | 0afe049bd7 |
|
@ -189,6 +189,7 @@ func twitchHTTPClient(call string, bearer string) (string, error) {
|
|||
var bearerHeader = "Bearer " + bearer
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req.Header.Add("Client-ID", ircBot.AppCredentials.ClientID)
|
||||
req.Header.Add("Authorization", bearerHeader)
|
||||
|
||||
client := &http.Client{}
|
||||
|
@ -207,14 +208,23 @@ func TwitchAdminHandler(response http.ResponseWriter, request *http.Request) {
|
|||
vars := mux.Vars(request)
|
||||
if vars["code"] != "" {
|
||||
response.Header().Add("Content-type", "text/plain")
|
||||
resp, err := http.PostForm(
|
||||
"https://id.twitch.tv/oauth2/token",
|
||||
url.Values{
|
||||
"client_id": {ircBot.AppCredentials.ClientID},
|
||||
"client_secret": {ircBot.AppCredentials.Password},
|
||||
"code": {vars["code"]},
|
||||
"grant_type": {"authorization_code"},
|
||||
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})
|
||||
form := url.Values{
|
||||
"client_id": {ircBot.AppCredentials.ClientID},
|
||||
"client_secret": {ircBot.AppCredentials.Password},
|
||||
"code": {vars["code"]},
|
||||
"grant_type": {"authorization_code"},
|
||||
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}}
|
||||
req, err := http.NewRequest("POST", "https://id.twitch.tv/oauth2/token", strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
response.WriteHeader(500)
|
||||
response.Header().Add("Content-type", "text/plain")
|
||||
fmt.Fprint(response, "ERROR: "+err.Error())
|
||||
return
|
||||
}
|
||||
req.Header.Add("Client-ID", ircBot.AppCredentials.ClientID)
|
||||
req.Header.Add("Authorization", "Bearer "+ircBot.AppCredentials.Password)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
response.WriteHeader(500)
|
||||
response.Header().Add("Content-type", "text/plain")
|
||||
|
@ -268,6 +278,10 @@ func TwitchAdminHandler(response http.ResponseWriter, request *http.Request) {
|
|||
fmt.Fprint(response, usersResponse)
|
||||
fmt.Fprint(response, "\n---\n")
|
||||
fmt.Fprint(response, usersObject)
|
||||
fmt.Fprint(response, "\n---\n")
|
||||
fmt.Fprint(response, "curl -H 'Authorization: Bearer "+oauthResponse.Access_token+
|
||||
"' -H 'Client-ID: "+ircBot.AppCredentials.ClientID+
|
||||
" -X GET https://api.twitch.tv/users")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue