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

changes related to suggestions from cozy forum

creating 2 endpoints to handle oauth transaction with enedis.
parent b91a04dd
No related branches found
No related tags found
Loading
Checking pipeline status
......@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"net/http"
"io/ioutil"
"strconv"
// "strings"
)
......@@ -16,18 +17,29 @@ func main() {
// Parse the flags
flag.Parse()
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
fmt.Println(query)
// host := strings.Split(query.Get("state"), "-")[1]
host := query.Get("state")
fmt.Println(host)
clientId := query.Get("client_id")
cozyOrigin := query.Get("redirect_uri") // here we use the redirect_uri param to transmit our stack url
state := query.Get("state")
fmt.Println(state)
response, err := http.Get("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/redirect&response_type=code&state="+ state +"-"+ cozyOrigin)
if err != nil {
fmt.Printf("%s", err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
fmt.Printf("%s\n", string(contents))
}
})
mux.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
state := strings.Split(query.Get("state"), "-")[0]
host := strings.Split(query.Get("state"), "-")[1]
usagePointId := query.Get("usage_point_id")
fmt.Println(usagePointId)
code := query.Get("code")
fmt.Println(code)
redir := "https://" + host + "/accounts/enedisoauth/redirect?code=" + code + "&state="+ state +"&usage_point_id=" + usagePointId
fmt.Println(redir)
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