Compare commits

...

5 Commits

View File

@ -21,11 +21,13 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"regexp"
"strings"
"time"
"github.com/garyburd/redigo/redis"
@ -160,7 +162,21 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
reqData.Set("code", code)
reqData.Set("client_id", sess.ClientID)
reqData.Set("redirect_uri", sess.RedirectURI)
resp, err := http.PostForm(sess.AuthorizationEndpoint, reqData)
// resp, err := http.PostForm(sess.AuthorizationEndpoint, reqData)
req, err := http.NewRequest(http.MethodPost, sess.AuthorizationEndpoint, strings.NewReader(reqData.Encode()))
if err != nil {
fmt.Fprintf(w, "ERROR: %q\n", err)
return
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
log.Println(req)
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Fprintf(w, "ERROR: %q\n", err)
return
@ -168,7 +184,8 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer resp.Body.Close()
if resp.StatusCode == 200 {
dec := json.NewDecoder(resp.Body)
input := io.TeeReader(resp.Body, os.Stderr)
dec := json.NewDecoder(input)
var authResponse authResponse
err = dec.Decode(&authResponse)
if err != nil {