From 547bc67280547343f72f4664109ad02695968263 Mon Sep 17 00:00:00 2001 From: "ext.sopra.yvallet@grandlyon.com" <ext.sopra.yvallet@grandlyon.com> Date: Tue, 20 Oct 2020 11:50:51 +0200 Subject: [PATCH] Parse params from body in grdf_token grdf --- main.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 9489501..48bb7c8 100644 --- a/main.go +++ b/main.go @@ -412,36 +412,44 @@ func main() { } pageContent := string(contents) //Check for client_id - clientIdStartIndex := strings.Index(pageContent, "client_id=") + clientIdKey := "client_id=" + clientIdLength := 22 + clientIdStartIndex := strings.Index(pageContent, clientIdKey) if clientIdStartIndex == -1 { log.Error("No client_id found") http.Error(w, http.StatusText(500), 500) } - clientIdStartIndex += 10 - clientId = pageContent[clientIdStartIndex : clientIdStartIndex+36] + clientIdStartIndex += len(clientIdKey) + clientId = pageContent[clientIdStartIndex : clientIdStartIndex+clientIdLength] //Check for client_secret - clientSecretStartIndex := strings.Index(pageContent, "client_secret=") + clientSecretKey := "client_secret=" + clientSecretLength := 14 + clientSecretStartIndex := strings.Index(pageContent, clientSecretKey) if clientSecretStartIndex == -1 { log.Error("No client_secret found") http.Error(w, http.StatusText(500), 500) } - clientSecretStartIndex += 14 - clientSecret = pageContent[clientSecretStartIndex : clientSecretStartIndex+36] + clientSecretStartIndex += len(clientSecretKey) + clientSecret = pageContent[clientSecretStartIndex : clientSecretStartIndex+clientSecretStartIndex] //Check for code - codeStartIndex := strings.Index(pageContent, "code=") + codeKey := "code=" + codeLength := 27 + codeStartIndex := strings.Index(pageContent, codeKey) if codeStartIndex == -1 { log.Info("No code found (optional param)") } else { - codeStartIndex += 5 - code = pageContent[codeStartIndex : codeStartIndex+30] + codeStartIndex += len(codeKey) + code = pageContent[codeStartIndex : codeStartIndex+codeLength] } //Check for grant_type - grandTypeStartIndex := strings.Index(pageContent, "grant_type=") + grandTypeKey := "grant_type=" + grandTypeLength := 27 + grandTypeStartIndex := strings.Index(pageContent, grandTypeKey) if grandTypeStartIndex == -1 { log.Error("No grant_type found") http.Error(w, http.StatusText(500), 500) } - grandTypeStartIndex += 11 + grandTypeStartIndex += len(grandTypeKey) tempGrandTypeString := pageContent[grandTypeStartIndex:] grandTypeEndIndex := strings.Index(tempGrandTypeString, "&") if grandTypeEndIndex == -1 { -- GitLab