From 10c6848c5c91a82f2b849ae0d65e409627771b46 Mon Sep 17 00:00:00 2001 From: Arzumify Date: Mon, 24 Jun 2024 22:59:53 +0100 Subject: [PATCH] Made the JSON marshal and unmarshal properly --- main.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 9887788..c08bd00 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "encoding/base64" "encoding/binary" "encoding/hex" + "encoding/json" "encoding/pem" "errors" "fmt" @@ -932,7 +933,14 @@ func main() { "PKCECode": code, "PKCEMethod": codeMethod, } - session.Set("activeLogin", sessionInfo) + + sessionInfoStr, err := json.Marshal(sessionInfo) + if err != nil { + log.Println("[ERROR] Unknown in /api/auth sessionInfoStr at", strconv.FormatInt(time.Now().Unix(), 10)+":", err) + c.String(500, "Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgerauth and refer to the docs for more info. Your error code is: UNKNOWN-API-AUTH-SESSIONINFO.") + return + } + session.Set("activeLogin", sessionInfoStr) err = session.Save() if err != nil { log.Println("[ERROR] Client-Server unknown in /api/auth session save at", strconv.FormatInt(time.Now().Unix(), 10)+":", err) @@ -992,7 +1000,8 @@ func main() { return } - activeLoginMap := activeLogin.(map[string]any) + var activeLoginMap map[string]any + err = json.Unmarshal([]byte(activeLogin.(string)), &activeLoginMap) openid, loginCode, PKCECode, PKCEMethod := activeLoginMap["openid"].(string), activeLoginMap["session"].(string), activeLoginMap["PKCECode"].(string), activeLoginMap["PKCEMethod"].(string) if loginCode != code { c.JSON(401, gin.H{"error": "Another login attempt is in progress or the login was never started"})