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)
|
vars := mux.Vars(request)
|
||||||
if vars["code"] != "" {
|
if vars["code"] != "" {
|
||||||
response.Header().Add("Content-type", "text/plain")
|
response.Header().Add("Content-type", "text/plain")
|
||||||
resp, err := http.PostForm(
|
form := url.Values{
|
||||||
"https://id.twitch.tv/oauth2/token",
|
"client_id": {ircBot.AppCredentials.ClientID},
|
||||||
url.Values{
|
"client_secret": {ircBot.AppCredentials.Password},
|
||||||
"client_id": {ircBot.AppCredentials.ClientID},
|
"code": {vars["code"]},
|
||||||
"client_secret": {ircBot.AppCredentials.Password},
|
"grant_type": {"authorization_code"},
|
||||||
"code": {vars["code"]},
|
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}}
|
||||||
"grant_type": {"authorization_code"},
|
req, err := http.NewRequest("POST", "https://id.twitch.tv/oauth2/token", strings.NewReader(form.Encode()))
|
||||||
"redirect_uri": {"https://" + ircBot.Config.ExternalUrl + "/twitchadmin"}})
|
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 {
|
if err != nil {
|
||||||
response.WriteHeader(500)
|
response.WriteHeader(500)
|
||||||
response.Header().Add("Content-type", "text/plain")
|
response.Header().Add("Content-type", "text/plain")
|
||||||
|
|
Loading…
Reference in New Issue