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

Format logs for token endpoint

parent 2d305989
No related branches found
No related tags found
No related merge requests found
Pipeline #5466 passed
...@@ -112,8 +112,9 @@ func main() { ...@@ -112,8 +112,9 @@ func main() {
grantType := "" grantType := ""
refreshToken := "" refreshToken := ""
// For request token params are into query parameters
if len(query) == 0 { if len(query) == 0 {
fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "No url params found - check in the body") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " - No params found in url query - Trying to catch them from body")
contents, err := ioutil.ReadAll(r.Body) contents, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
...@@ -122,7 +123,7 @@ func main() { ...@@ -122,7 +123,7 @@ func main() {
//Check for client_id //Check for client_id
clientIdStartIndex := strings.Index(pageContent, "client_id=") clientIdStartIndex := strings.Index(pageContent, "client_id=")
if clientIdStartIndex == -1 { if clientIdStartIndex == -1 {
fmt.Println("No client_id found") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " - Error - No client_id found")
http.Error(w, http.StatusText(500), 500) http.Error(w, http.StatusText(500), 500)
} }
clientIdStartIndex += 10 clientIdStartIndex += 10
...@@ -130,7 +131,7 @@ func main() { ...@@ -130,7 +131,7 @@ func main() {
//Check for client_secret //Check for client_secret
clientSecretStartIndex := strings.Index(pageContent, "client_secret=") clientSecretStartIndex := strings.Index(pageContent, "client_secret=")
if clientSecretStartIndex == -1 { if clientSecretStartIndex == -1 {
fmt.Println("No client_secret found") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " - Error - No client_secret found")
http.Error(w, http.StatusText(500), 500) http.Error(w, http.StatusText(500), 500)
} }
clientSecretStartIndex += 14 clientSecretStartIndex += 14
...@@ -138,7 +139,7 @@ func main() { ...@@ -138,7 +139,7 @@ func main() {
//Check for code //Check for code
codeStartIndex := strings.Index(pageContent, "code=") codeStartIndex := strings.Index(pageContent, "code=")
if codeStartIndex == -1 { if codeStartIndex == -1 {
fmt.Println("No code found") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " - Info - No code found (optionnal param)")
} else { } else {
codeStartIndex += 5 codeStartIndex += 5
code = pageContent[codeStartIndex:codeStartIndex + 30] code = pageContent[codeStartIndex:codeStartIndex + 30]
...@@ -146,25 +147,27 @@ func main() { ...@@ -146,25 +147,27 @@ func main() {
//Check for grant_type //Check for grant_type
grandTypeStartIndex := strings.Index(pageContent, "grant_type=") grandTypeStartIndex := strings.Index(pageContent, "grant_type=")
if grandTypeStartIndex == -1 { if grandTypeStartIndex == -1 {
fmt.Println("No grant_type found") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " - Error - No grant_type found")
http.Error(w, http.StatusText(500), 500) http.Error(w, http.StatusText(500), 500)
} }
grandTypeStartIndex += 11 grandTypeStartIndex += 11
tempGrandTypeString := pageContent[grandTypeStartIndex:len(pageContent)] tempGrandTypeString := pageContent[grandTypeStartIndex:len(pageContent)]
grandTypeEndIndex := strings.Index(tempGrandTypeString, "&") grandTypeEndIndex := strings.Index(tempGrandTypeString, "&")
if grandTypeEndIndex == -1 { if grandTypeEndIndex == -1 {
fmt.Println("No closing tag for grant_type found") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " - Error - No closing tag for grant_type found")
http.Error(w, http.StatusText(500), 500) http.Error(w, http.StatusText(500), 500)
} }
grantType = tempGrandTypeString[0:grandTypeEndIndex] grantType = tempGrandTypeString[0:grandTypeEndIndex]
//Check for refresh_token //Check for refresh_token
refershTokenStartIndex := strings.Index(pageContent, "refresh_token=") refershTokenStartIndex := strings.Index(pageContent, "refresh_token=")
if refershTokenStartIndex == -1 { if refershTokenStartIndex == -1 {
fmt.Println("No code found") fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " - Error - No refresh_token found")
http.Error(w, http.StatusText(500), 500)
} }
refershTokenStartIndex += 14 refershTokenStartIndex += 14
refreshToken = pageContent[refershTokenStartIndex:refershTokenStartIndex + 46] refreshToken = pageContent[refershTokenStartIndex:refershTokenStartIndex + 46]
} else { } else {
// Retrieve params from query
clientId = query.Get("client_id") clientId = query.Get("client_id")
clientSecret = query.Get("client_secret") clientSecret = query.Get("client_secret")
code = query.Get("code") code = query.Get("code")
...@@ -178,7 +181,6 @@ func main() { ...@@ -178,7 +181,6 @@ func main() {
fmt.Printf("grant_type: %s\n", grantType) fmt.Printf("grant_type: %s\n", grantType)
fmt.Printf("refresh_token: %s\n", refreshToken) fmt.Printf("refresh_token: %s\n", refreshToken)
tokenUrl := "https://gw.hml.api.enedis.fr/v1/oauth2/token" tokenUrl := "https://gw.hml.api.enedis.fr/v1/oauth2/token"
data := url.Values{} data := url.Values{}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment