Jan Dittberner
16a3dbedc8
- move internal code to internal directory - add translations for texts on missing email in client certificate page - add error handling for missing login_challenge request parameter - add Markdown support via goldmark - use https:// URLs in Apache license headers
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
/*
|
|
Copyright 2020-2023 CAcert Inc.
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/ory/hydra-client-go/client/admin"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type LogoutHandler struct {
|
|
adminClient admin.ClientService
|
|
logger *log.Logger
|
|
}
|
|
|
|
func (h *LogoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
const Ten = 10 * time.Second
|
|
|
|
challenge := r.URL.Query().Get("logout_challenge")
|
|
h.logger.Debugf("received challenge %s\n", challenge)
|
|
|
|
logoutRequest, err := h.adminClient.GetLogoutRequest(
|
|
admin.NewGetLogoutRequestParams().WithLogoutChallenge(challenge).WithTimeout(Ten))
|
|
if err != nil {
|
|
h.logger.Errorf("error getting logout requests: %v", err)
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
}
|
|
|
|
h.logger.Debugf("received logout request: %#v", logoutRequest.Payload)
|
|
|
|
acceptLogoutRequest, err := h.adminClient.AcceptLogoutRequest(
|
|
admin.NewAcceptLogoutRequestParams().WithLogoutChallenge(challenge))
|
|
if err != nil {
|
|
h.logger.Errorf("error accepting logout: %v", err)
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
}
|
|
|
|
w.Header().Set("Location", *acceptLogoutRequest.GetPayload().RedirectTo)
|
|
w.WriteHeader(http.StatusFound)
|
|
}
|
|
|
|
func NewLogoutHandler(logger *log.Logger, adminClient admin.ClientService) *LogoutHandler {
|
|
return &LogoutHandler{
|
|
logger: logger,
|
|
adminClient: adminClient,
|
|
}
|
|
}
|
|
|
|
type LogoutSuccessHandler struct {
|
|
}
|
|
|
|
func (l *LogoutSuccessHandler) ServeHTTP(_ http.ResponseWriter, _ *http.Request) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func NewLogoutSuccessHandler() *LogoutSuccessHandler {
|
|
return &LogoutSuccessHandler{}
|
|
}
|