mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 07:12:46 +01:00
16
cookie.go
16
cookie.go
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -22,15 +23,21 @@ func stateCookie(r *http.Request) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return stateCookie.Value, nil
|
||||
}
|
||||
|
||||
func setClaimsCookie(w http.ResponseWriter, claims map[string]interface{}) {
|
||||
b, _ := json.Marshal(claims)
|
||||
func setClaimsCookie(w http.ResponseWriter, claims map[string]any) {
|
||||
b, err := json.Marshal(claims)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
return
|
||||
}
|
||||
http.SetCookie(w, &http.Cookie{Name: userSessionCookie, Value: base64.StdEncoding.EncodeToString(b)})
|
||||
}
|
||||
|
||||
func claimsCookie(r *http.Request) (map[string]interface{}, bool, error) {
|
||||
func claimsCookie(r *http.Request) (map[string]any, bool, error) {
|
||||
userCookie, err := r.Cookie(userSessionCookie)
|
||||
if err != nil {
|
||||
return nil, true, nil
|
||||
@@ -41,9 +48,10 @@ func claimsCookie(r *http.Request) (map[string]interface{}, bool, error) {
|
||||
return nil, false, fmt.Errorf("could not decode cookie: %w", err)
|
||||
}
|
||||
|
||||
var claims map[string]interface{}
|
||||
var claims map[string]any
|
||||
if err := json.Unmarshal(b, &claims); err != nil {
|
||||
return nil, false, errors.New("claims not in session")
|
||||
}
|
||||
|
||||
return claims, false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user