From 375e1b4d3feb98c43ed39488cfe5ba2266e44abd Mon Sep 17 00:00:00 2001 From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com> Date: Fri, 15 May 2020 15:54:12 +0200 Subject: [PATCH] Change auth endpoint - Remove test logs - Change reply uri --- main.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 7864ee8..4d44cdb 100644 --- a/main.go +++ b/main.go @@ -36,20 +36,7 @@ func main() { mux.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) { fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- New auth request") query := r.URL.Query() - fmt.Println(query) - - fmt.Println("---------------------------") - fmt.Println("RequestURI", r.RequestURI) - fmt.Println("RemoteAddr ", r.RemoteAddr) - fmt.Println("Trailer ", r.Trailer) - fmt.Println("Host ", r.Host ) - fmt.Println("Header", r.Header) - fmt.Println("referer", r.Header["Referer"]) - fmt.Println("referer", r.Header.Get("Referer")) - fmt.Println("URL Hostname()", r.URL.Hostname()) - fmt.Println("URL RequestURI()", r.URL.RequestURI()) - fmt.Println("URL String()", r.URL.String()) - fmt.Println("---------------------------") + fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- Query received - ", query) clientId := query.Get("client_id") state := query.Get("state") @@ -69,14 +56,16 @@ func main() { if err != nil { fmt.Println(err) } - // Define the host - host := "https://" + r.Host - fmt.Println("host", r.Host) + // Define the replyUri + referer := r.Header.Get("Referer") + replyUri := strings.Replace(referer, "home.", "", 1) + replyUri = redirectUri + "accounts/enedis-konnector/redirect" + fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- Redirect to - ", replyUri) // Get the response body as a string pageContentString := string(contents) // Replace redirectUri by the host in the body - pageContentString = strings.ReplaceAll(pageContentString, redirectUri, host) + pageContentString = strings.ReplaceAll(pageContentString, redirectUri, replyUri) fmt.Println(pageContentString) // Convert string to byte for response writting newPageContentByte := []byte(pageContentString) -- GitLab