From 723602dc6eceed3c157d9872a6a96cb938d9e151 Mon Sep 17 00:00:00 2001
From: zachmann <gabriel.zachmann@kit.edu>
Date: Mon, 18 Oct 2021 09:52:56 +0200
Subject: [PATCH] fix response type on oidc error on redirect

---
 internal/endpoints/redirect/redirectEndpoint.go | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/internal/endpoints/redirect/redirectEndpoint.go b/internal/endpoints/redirect/redirectEndpoint.go
index 802d64d1..f1ed0a2a 100644
--- a/internal/endpoints/redirect/redirectEndpoint.go
+++ b/internal/endpoints/redirect/redirectEndpoint.go
@@ -13,7 +13,6 @@ import (
 	"github.com/oidc-mytoken/server/internal/db/dbrepo/authcodeinforepo"
 	"github.com/oidc-mytoken/server/internal/db/dbrepo/authcodeinforepo/state"
 	"github.com/oidc-mytoken/server/internal/db/dbrepo/mytokenrepo/transfercoderepo"
-	"github.com/oidc-mytoken/server/internal/model"
 	"github.com/oidc-mytoken/server/internal/oidc/authcode"
 	"github.com/oidc-mytoken/server/internal/server/httpStatus"
 	"github.com/oidc-mytoken/server/internal/utils/ctxUtils"
@@ -40,11 +39,13 @@ func HandleOIDCRedirect(ctx *fiber.Ctx) error {
 			}
 		}
 		oidcErrorDescription := ctx.Query("error_description")
-		errorRes := model.Response{
-			Status:   httpStatus.StatusOIDPError,
-			Response: pkgModel.OIDCError(oidcError, oidcErrorDescription),
-		}
-		return errorRes.Send(ctx)
+		return ctx.Status(httpStatus.StatusOIDPError).Render(
+			"sites/error", map[string]interface{}{
+				"empty-navbar":  true,
+				"error-heading": "OIDC error",
+				"msg":           pkgModel.OIDCError(oidcError, oidcErrorDescription).CombinedMessage(),
+			}, "layouts/main",
+		)
 	}
 	code := ctx.Query("code")
 	res := authcode.CodeExchange(oState, code, *ctxUtils.ClientMetaData(ctx))
@@ -52,7 +53,7 @@ func HandleOIDCRedirect(ctx *fiber.Ctx) error {
 	if fasthttp.StatusCodeIsRedirect(res.Status) {
 		return res.Send(ctx)
 	}
-	return ctx.Render(
+	return ctx.Status(res.Status).Render(
 		"sites/error", map[string]interface{}{
 			"empty-navbar":  true,
 			"error-heading": http.StatusText(res.Status),
-- 
GitLab