forked from u5surf/auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logout.go
36 lines (29 loc) · 909 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
// Copyright 2018 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package main
import (
"net/http"
"github.com/go-kit/kit/log"
"github.com/gorilla/mux"
)
func addLogoutRoutes(router *mux.Router, logger log.Logger, auth authable) {
router.Methods("DELETE").Path("/users/login").HandlerFunc(logoutRoute(auth))
}
func logoutRoute(auth authable) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w = wrapResponseWriter(w, r, "logoutRoute")
userId, err := extractUserId(auth, r)
if err != nil {
w.WriteHeader(http.StatusOK)
return
}
if err := auth.invalidateCookies(userId); err != nil {
logger.Log("logout", err)
w.WriteHeader(http.StatusBadRequest)
return
}
authInactivations.With("method", "web").Add(1)
w.WriteHeader(http.StatusOK)
}
}