diff --git a/main.go b/main.go index 2a78235dd71a56b78ee81cdbb1fe2799b7b0ed5c..7a3a9282fa8135b7dc6695f40b825c975bcd4ee6 100644 --- a/main.go +++ b/main.go @@ -45,26 +45,10 @@ func main() { redirectUri := "https://oauth-proxy.wf.alpha.grandlyon.com/redirect" responseType := "code" - authReq := "https://mon-compte-particulier.enedis.fr/dataconnect/v1/oauth2/authorize?client_id="+ clientId +"&duration=P6M&redirect_uri="+ redirectUri +"&response_type="+ responseType +"&state="+ state +"-"+ cozyOrigin + redirectUrl := "https://mon-compte-particulier.enedis.fr/dataconnect/v1/oauth2/authorize?client_id="+ clientId +"&duration=P6M&redirect_uri="+ redirectUri +"&response_type="+ responseType +"&state="+ state +"-"+ cozyOrigin - fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- Send request to auth endpoint", authReq) - response, err := http.Get(authReq) - fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- Endpoint response with status", response.Status) - if err != nil { - fmt.Println(err) - } else { - defer response.Body.Close() - contents, err := ioutil.ReadAll(response.Body) - if err != nil { - fmt.Println(err) - } - - if response.StatusCode >= 200 && response.StatusCode <= 299 { - w.Write(contents) - } else { - http.Error(w, http.StatusText(response.StatusCode), response.StatusCode) - } - } + fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- Redirect to - ", redirectUrl) + http.Redirect(w, r, redirectUrl, 302) }) mux.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {