Browse Source

Oauth is painful

Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
master v0.0.9
Martyn 1 year ago
parent
commit
0afe049bd7
1 changed files with 16 additions and 8 deletions
  1. +16
    -8
      internal/webserver/webserver.go

+ 16
- 8
internal/webserver/webserver.go View File

@ -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{
"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.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…
Cancel
Save