Oauth is painful
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
6f1f4d0750
commit
0afe049bd7
|
@ -207,14 +207,22 @@ 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{
|
||||
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"}})
|
||||
"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.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
response.WriteHeader(500)
|
||||
response.Header().Add("Content-type", "text/plain")
|
||||
|
|
Loading…
Reference in New Issue