@@ -41,6 +41,7 @@ type Session struct {
4141 LastSeen time.Time `json:"last_seen"`
4242 LongRun bool `json:"long_run"`
4343 ShortRun bool `json:"short_run"`
44+ SID string `json:"sid,omitempty"` // only present with OIDC
4445}
4546
4647// DocType implements couchdb.Doc
@@ -101,14 +102,15 @@ func (s *Session) OlderThan(t time.Duration) bool {
101102}
102103
103104// New creates a session in couchdb for the given instance
104- func New (i * instance.Instance , duration Duration ) (* Session , error ) {
105+ func New (i * instance.Instance , duration Duration , sid string ) (* Session , error ) {
105106 now := time .Now ()
106107 s := & Session {
107108 instance : i ,
108109 LastSeen : now ,
109110 CreatedAt : now ,
110111 ShortRun : duration == ShortRun ,
111112 LongRun : duration == LongRun ,
113+ SID : sid ,
112114 }
113115 if err := couchdb .CreateDoc (i , s ); err != nil {
114116 return nil , err
@@ -302,6 +304,21 @@ func DeleteOthers(i *instance.Instance, selfSessionID string) error {
302304 return nil
303305}
304306
307+ // DeleteBySID is used for the OIDC back-channel logout. It deletes the sessions
308+ // for the current device of the user.
309+ func DeleteBySID (inst * instance.Instance , sid string ) error {
310+ return couchdb .ForeachDocs (inst , consts .Sessions , func (_ string , data json.RawMessage ) error {
311+ var s Session
312+ if err := json .Unmarshal (data , & s ); err != nil {
313+ return err
314+ }
315+ if s .SID == sid {
316+ s .Delete (inst )
317+ }
318+ return nil
319+ })
320+ }
321+
305322// cookieSessionMACConfig returns the options to authenticate the session
306323// cookie.
307324//
0 commit comments