-
-
Notifications
You must be signed in to change notification settings - Fork 963
/
handler.go
68 lines (58 loc) · 1.78 KB
/
handler.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package logout
import (
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/ory/kratos/driver/configuration"
"github.com/ory/kratos/selfservice/errorx"
"github.com/ory/kratos/session"
"github.com/ory/kratos/x"
)
const (
BrowserLogoutPath = "/self-service/browser/flows/logout"
)
type (
handlerDependencies interface {
x.CSRFProvider
session.ManagementProvider
errorx.ManagementProvider
}
HandlerProvider interface {
LogoutHandler() *Handler
}
Handler struct {
c configuration.Provider
d handlerDependencies
}
)
func NewHandler(d handlerDependencies, c configuration.Provider) *Handler {
return &Handler{d: d, c: c}
}
func (h *Handler) RegisterPublicRoutes(router *x.RouterPublic) {
router.GET(BrowserLogoutPath, h.logout)
}
// swagger:route GET /self-service/browser/flows/logout public initializeSelfServiceBrowserLogoutFlow
//
// Initialize Browser-Based Logout User Flow
//
// This endpoint initializes a logout flow.
//
// > This endpoint is NOT INTENDED for API clients and only works
// with browsers (Chrome, Firefox, ...).
//
// On successful logout, the browser will be redirected (HTTP 302 Found) to `urls.default_return_to`.
//
// More information can be found at [ORY Kratos User Logout Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-logout).
//
// Schemes: http, https
//
// Responses:
// 302: emptyResponse
// 500: genericError
func (h *Handler) logout(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
_ = h.d.CSRFHandler().RegenerateToken(w, r)
if err := h.d.SessionManager().PurgeFromRequest(r.Context(), w, r); err != nil {
h.d.SelfServiceErrorManager().ForwardError(r.Context(), w, r, err)
return
}
http.Redirect(w, r, h.c.SelfServiceLogoutRedirectURL().String(), http.StatusFound)
}