diff --git a/internal/api/v1/v1.go b/internal/api/v1/v1.go index 568ff05..b795b15 100644 --- a/internal/api/v1/v1.go +++ b/internal/api/v1/v1.go @@ -99,13 +99,13 @@ func (v *V1) App() *fiber.App { func (v *V1) Logout(ctx *fiber.Ctx) error { v.logger.Debug().Msgf("received Logout from %s", ctx.IP()) - err := v.options.Controller().LogoutSession(ctx) - if err != nil { + cont, err := v.options.Controller().LogoutSession(ctx) + if !cont { return err } - err = v.options.Controller().LogoutServiceSession(ctx) - if err != nil { + cont, err = v.options.Controller().LogoutServiceSession(ctx) + if !cont { return err } diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 7d6c3a4..c934895 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -506,39 +506,39 @@ func (m *Controller) GetServiceSessionFromContext(ctx *fiber.Ctx) (*servicesessi return sess, nil } -func (m *Controller) LogoutSession(ctx *fiber.Ctx) error { +func (m *Controller) LogoutSession(ctx *fiber.Ctx) (bool, error) { cookie := ctx.Cookies(CookieKeyString) if cookie != "" { sess, err := m.getSession(ctx, cookie) if sess == nil { - return err + return false, err } err = m.storage.DeleteSession(ctx.Context(), sess.ID) if err != nil { m.logger.Error().Err(err).Msg("failed to delete session") - return ctx.Status(fiber.StatusInternalServerError).SendString("failed to delete session") + return false, ctx.Status(fiber.StatusInternalServerError).SendString("failed to delete session") } } ctx.ClearCookie(CookieKeyString) - return nil + return true, nil } -func (m *Controller) LogoutServiceSession(ctx *fiber.Ctx) error { +func (m *Controller) LogoutServiceSession(ctx *fiber.Ctx) (bool, error) { authHeader := ctx.Request().Header.PeekBytes(AuthorizationHeader) if len(authHeader) > len(BearerHeader) { if !bytes.Equal(authHeader[:len(BearerHeader)], BearerHeader) { - return nil + return true, nil } authHeader = authHeader[len(BearerHeader):] if !bytes.HasPrefix(authHeader, auth.ServiceSessionPrefix) { - return nil + return true, nil } keySplit := bytes.Split(authHeader, KeyDelimiter) if len(keySplit) != 2 { - return nil + return true, nil } keyID := string(keySplit[0]) @@ -546,16 +546,16 @@ func (m *Controller) LogoutServiceSession(ctx *fiber.Ctx) error { sess, err := m.getServiceSession(ctx, keyID, keySecret) if sess == nil { - return err + return false, err } err = m.storage.DeleteServiceSession(ctx.Context(), sess.ID) if err != nil { m.logger.Error().Err(err).Msg("failed to delete service session") - return ctx.Status(fiber.StatusInternalServerError).SendString("failed to delete service session") + return false, ctx.Status(fiber.StatusInternalServerError).SendString("failed to delete service session") } } - return nil + return true, nil } func (m *Controller) getSession(ctx *fiber.Ctx, cookie string) (*session.Session, error) {