diff options
| author | Melonai <einebeere@gmail.com> | 2021-07-26 23:50:43 +0200 |
|---|---|---|
| committer | Melonai <einebeere@gmail.com> | 2021-07-26 23:50:43 +0200 |
| commit | 175da8f22cd791e81338fe61e6099125868cf5a0 (patch) | |
| tree | 91a234d8aafd54be34aae5ff5b948b34e52fb020 /handlers/passthrough.go | |
| parent | 83a8214119eccb39f4c38e7b1ae54daebdeb0184 (diff) | |
| download | portgate-175da8f22cd791e81338fe61e6099125868cf5a0.tar.zst portgate-175da8f22cd791e81338fe61e6099125868cf5a0.zip | |
Basic Authentication and Authorization
Diffstat (limited to 'handlers/passthrough.go')
| -rw-r--r-- | handlers/passthrough.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/handlers/passthrough.go b/handlers/passthrough.go index b2daa88..3f8aafc 100644 --- a/handlers/passthrough.go +++ b/handlers/passthrough.go @@ -2,6 +2,7 @@ package handlers import ( "github.com/valyala/fasthttp" + "net/http" "portgate" ) @@ -9,9 +10,14 @@ import ( // If the user is authorized they are allowed to pass, otherwise they should be redirected to // the authentication page. (/_portgate) func (h *RequestHandler) handlePassthroughRequest(ctx *fasthttp.RequestCtx, p portgate.Path) { - // TODO: Check authorization. // TODO: Check whether port is allowed to be accessed. + // Check whether given cookie is ok, if not redirect to the authentication page. + if !portgate.VerifyTokenFromCookie(h.config, ctx) { + ctx.Redirect("/_portgate", http.StatusTemporaryRedirect) + return + } + // We reuse the request given to us by the user with minor changes to route it to the // destination host. ctx.Request.SetRequestURI(h.config.MakeUrl(p)) |
