Skip to content
Snippets Groups Projects
Commit 5a890bc9 authored by Hugo NOUTS's avatar Hugo NOUTS
Browse files

testing with hard coded variable of the cozy stack caller

to check if the token post error is from a wrong redirect_uri stored in the document.
parent 4331e918
No related branches found
No related tags found
No related merge requests found
Pipeline #5017 passed
......@@ -94,18 +94,64 @@ func main() {
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
fmt.Println(query)
state := strings.Split(query.Get("state"), "-")[0]
host := strings.Split(query.Get("state"), "-")[1]
fmt.Println(host)
fmt.Println(state)
usagePointId := query.Get("usage_point_id")
code := query.Get("code")
redir := "https://" + host + "/accounts/enedisoauth/redirect?code=" + code + "&state="+ state +"&usage_point_id=" + usagePointId
fmt.Println(redir)
http.Redirect(w, r, redir, 302)
clientId := query.Get("client_id")
cozyOrigin := "hugo.pchugo.wf.alpha.grandlyon.com"
state := query.Get("state")
authReq := "https://gw.hml.api.enedis.fr/group/espace-particuliers/consentement-linky/oauth2/authorize?client_id="+ clientId +"&duration=P6M&redirect_uri=https://oauth-proxy.wf.alpha.grandlyon.com/&response_type=code&state="+ state +"-"+ cozyOrigin
fmt.Println(authReq)
response, err := http.Get(authReq)
if err != nil {
fmt.Println(err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println(err)
}
pageContent := string(contents)
codeStartIndex := strings.Index(pageContent, "?code=")
if codeStartIndex == -1 {
fmt.Println("No code found")
}
codeStartIndex += 6
codeEndIndex := strings.Index(pageContent, "&state=")
if codeEndIndex == -1 {
fmt.Println("No closing tag for code found.")
}
stateStartIndex := strings.Index(pageContent, "&state=")
if stateStartIndex == -1 {
fmt.Println("No state found")
}
stateStartIndex += 7
stateEndIndex := strings.Index(pageContent, "&usage_point_id=")
if stateEndIndex == -1 {
fmt.Println("No closing tag for state found.")
}
usageStartIndex := strings.Index(pageContent, "&usage_point_id=")
if usageStartIndex == -1 {
fmt.Println("No usage found")
}
usageStartIndex += 16
usageEndIndex := strings.Index(pageContent, "&usage_point_id=")
if usageEndIndex == -1 {
fmt.Println("No closing tag for usage found.")
}
usageEndIndex += 30
pageCode := string([]byte(pageContent[codeStartIndex:codeEndIndex]))
pageState := string([]byte(pageContent[stateStartIndex:stateEndIndex]))
pageUsage := string([]byte(pageContent[usageStartIndex:usageEndIndex]))
fmt.Printf("Page code: %s\n", pageCode)
fmt.Printf("Page state: %s\n", pageState)
fmt.Printf("Page usage: %s\n", pageUsage)
state := strings.Split(pageState, "-")[0]
host := strings.Split(pageState, "-")[1]
redir := "https://" + host + "/accounts/enedisoauth/redirect?code=" + pageCode + "&state="+ state +"&usage_point_id=" + pageUsage
fmt.Println(redir)
http.Redirect(w, r, redir, 302)
}
})
http.ListenAndServe(":"+strconv.Itoa(*httpPort), mux)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment