Skip to content

Commit

Permalink
refactor: use session token as cookie identifier
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Existing login sessions will no longer be valid because the session cookie data model changed. If you apply this patch, your users will need to sign in again.
  • Loading branch information
aeneasr committed Aug 25, 2020
1 parent ec6ca20 commit 60fd9c2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions session/manager_http.go
Expand Up @@ -80,7 +80,7 @@ func (s *ManagerHTTP) IssueCookie(ctx context.Context, w http.ResponseWriter, r
cookie.Options.MaxAge = int(s.c.SessionLifespan().Seconds())
}

cookie.Values["sid"] = session.ID.String()
cookie.Values["session_token"] = session.Token
if err := cookie.Save(r, w); err != nil {
return errors.WithStack(err)
}
Expand All @@ -93,12 +93,12 @@ func (s *ManagerHTTP) FetchFromRequest(ctx context.Context, r *http.Request) (*S
return nil, errors.WithStack(ErrNoActiveSessionFound.WithWrap(err).WithDebugf("%s", err))
}

sid, ok := cookie.Values["sid"].(string)
token, ok := cookie.Values["session_token"].(string)
if !ok {
return nil, errors.WithStack(ErrNoActiveSessionFound)
}

se, err := s.r.SessionPersister().GetSession(ctx, x.ParseUUID(sid))
se, err := s.r.SessionPersister().GetSessionFromToken(ctx, token)
if err != nil {
if errors.Is(err, herodot.ErrNotFound) || errors.Is(err, sqlcon.ErrNoRows) {
return nil, errors.WithStack(ErrNoActiveSessionFound)
Expand All @@ -111,7 +111,6 @@ func (s *ManagerHTTP) FetchFromRequest(ctx context.Context, r *http.Request) (*S
}

se.Identity = se.Identity.CopyWithoutCredentials()

return se, nil
}

Expand Down

0 comments on commit 60fd9c2

Please sign in to comment.