Made the JSON marshal and unmarshal properly

This commit is contained in:
Tracker-Friendly 2024-06-24 22:59:53 +01:00
parent 447fb7a4fa
commit 10c6848c5c
1 changed files with 11 additions and 2 deletions

13
main.go
View File

@ -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"})