-
Notifications
You must be signed in to change notification settings - Fork 90
/
logout.go
41 lines (34 loc) · 942 Bytes
/
logout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package handlers
import (
"net/http"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/session"
"github.com/replicatedhq/kots/pkg/store"
)
func (h *Handler) Logout(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") == "" {
w.WriteHeader(http.StatusNoContent)
return
}
sess, err := session.Parse(store.GetStore(), r.Header.Get("Authorization"))
if err != nil {
if store.GetStore().IsNotFound(err) {
w.WriteHeader(http.StatusNoContent)
return
}
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
w.WriteHeader(http.StatusNoContent)
return
}
if err := store.GetStore().DeleteSession(sess.ID); err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
}