Skip to content

Commit

Permalink
bug: oauth fix (#1033)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Jun 16, 2024
1 parent 91a5dfb commit b731b2e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions backend/integrations/oauth/soth/sothic/sothic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ const (
ProviderParamKey key = iota
)

// Session can/should be set by applications using sothic.
var (
// Session can/should be set by applications using sothic.
SessionStore *session.Store
encrypter func(string) (string, error)
decrypter func(string) (string, error)

encrypter func(string) (string, error)
decrypter func(string) (string, error)
)

// MUST be called before using the package
Expand Down Expand Up @@ -314,6 +315,7 @@ func GetFromSession(key string, c *fiber.Ctx) (string, error) {

value, err := getSessionValue(session, key)
if err != nil {
slog.Error("error getting session value", "error", err)
return "", errors.New("could not find a matching session for this request")
}

Expand All @@ -323,11 +325,15 @@ func GetFromSession(key string, c *fiber.Ctx) (string, error) {
func getSessionValue(store *session.Session, key string) (string, error) {
value := store.Get(key)
if value == nil {
return "", errors.New("could not find a matching session for this request")
return "", fmt.Errorf("key %s not found in session", key)
}

decrypted, err := decrypter(value.(string))
if err != nil {
return "", err
}

rdata := strings.NewReader(value.(string))
r, err := gzip.NewReader(rdata)
r, err := gzip.NewReader(strings.NewReader(decrypted))
if err != nil {
return "", err
}
Expand All @@ -336,7 +342,7 @@ func getSessionValue(store *session.Session, key string) (string, error) {
return "", err
}

return decrypter(string(s))
return string(s), nil
}

func updateSessionValue(session *session.Session, key, value string) error {
Expand Down

0 comments on commit b731b2e

Please sign in to comment.