Skip to content
Snippets Groups Projects
Commit 51f8cbd5 authored by Yoan VALLET's avatar Yoan VALLET
Browse files

update main.go - fix redir on redirect endpoint

parent 74c0148a
Branches
No related tags found
No related merge requests found
Pipeline #5390 passed
...@@ -125,10 +125,11 @@ func main() { ...@@ -125,10 +125,11 @@ func main() {
clientId := query.Get("client_id") clientId := query.Get("client_id")
state := query.Get("state") state := query.Get("state")
cozyOrigin := query.Get("redirect_uri") // here we use the redirect_uri param to transmit our stack url
redirectUri := "https://oauth-proxy.wf.alpha.grandlyon.com/" redirectUri := "https://oauth-proxy.wf.alpha.grandlyon.com/"
responseType := "code" responseType := "code"
authReq := "https://gw.hml.api.enedis.fr/group/espace-particuliers/consentement-linky/oauth2/authorize?client_id="+ clientId +"&duration=P6M&redirect_uri="+ redirectUri +"&response_type="+ responseType +"&state="+ state authReq := "https://gw.hml.api.enedis.fr/group/espace-particuliers/consentement-linky/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) fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- Send request to auth endpoint", authReq)
response, err := http.Get(authReq) response, err := http.Get(authReq)
...@@ -168,28 +169,14 @@ func main() { ...@@ -168,28 +169,14 @@ func main() {
fmt.Println(query) fmt.Println(query)
code := query.Get("code") code := query.Get("code")
state := query.Get("state") req_state := query.Get("state")
state := strings.Split(req_state, "-")[0]
host := strings.Split(req_state, "-")[1]
usagePointId := query.Get("usage_point_id") usagePointId := query.Get("usage_point_id")
// Get the redirect uri from the referer redir := host + "?code=" + code + "&state="+ state +"&usage_point_id=" + usagePointId
referer := r.Header.Get("Referer") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "- Redirect to -", redir)
redirectUri := ""
redirectStartIndex := strings.Index(referer, "&redirect_uri=")
if redirectStartIndex == -1 {
fmt.Println("No redirect found")
}
redirectStartIndex += len("&redirect_uri=")
splitRefer := string([]byte(referer[redirectStartIndex:len(referer)]))
fmt.Println(splitRefer)
redirectEndIndex := strings.Index(splitRefer, "&")
if redirectEndIndex == -1 {
redirectUri = splitRefer
}
redirectUri = string([]byte(splitRefer[0:redirectEndIndex]))
fmt.Println(redirectUri)
redir := "https://" + redirectUri + "/accounts/enedis-konnector/redirect?code=" + code + "&state="+ state +"&usage_point_id=" + usagePointId
fmt.Println(redir)
http.Redirect(w, r, redir, 302) http.Redirect(w, r, redir, 302)
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment