generated from resonatecoop/id-server-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logout.go
41 lines (34 loc) · 975 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 web
import (
"net/http"
)
func (s *Service) logout(w http.ResponseWriter, r *http.Request) {
// Get the session service from the request context
sessionService, err := getSessionService(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Get the user session
userSession, err := sessionService.GetUserSession()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Delete the access and refresh tokens
s.oauthService.ClearUserTokens(userSession)
// Delete the user session
err = sessionService.ClearUserSession()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Delete the checkout session
err = sessionService.ClearCheckoutSession()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Redirect back to the login page
redirectWithQueryString("/web/login", r.URL.Query(), w, r)
}