From 0fa8e1fb255d184323ba73876d48581607f09c5e Mon Sep 17 00:00:00 2001 From: olegfomenko2002 Date: Wed, 24 Jan 2024 12:59:17 +0200 Subject: [PATCH] update auth middleware --- go.mod | 2 +- go.sum | 2 ++ internal/services/api/handlers/middleware.go | 10 ++-------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 58920ea..d8a8227 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-chi/chi v4.1.2+incompatible github.com/go-ozzo/ozzo-validation/v4 v4.2.1 github.com/google/uuid v1.3.0 - github.com/rarimo/rarime-auth-svc v0.0.1-rc8 + github.com/rarimo/rarime-auth-svc v0.0.1-rc9 github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a github.com/rubenv/sql-migrate v1.5.2 gitlab.com/distributed_lab/ape v1.7.1 diff --git a/go.sum b/go.sum index 243cae3..dfbafbd 100644 --- a/go.sum +++ b/go.sum @@ -203,6 +203,8 @@ github.com/rarimo/rarime-auth-svc v0.0.1-rc7 h1:+ibnWRdc+fi27JrR3vOPLIXgOdePb29K github.com/rarimo/rarime-auth-svc v0.0.1-rc7/go.mod h1:48c8FsJixnLeWx8F8MDy79FvhU1r0oTU11mwP3JPngQ= github.com/rarimo/rarime-auth-svc v0.0.1-rc8 h1:MBx51/ynR8BaRz5HvcbatYe4hnB2ZDVwM7cmGEepg+Y= github.com/rarimo/rarime-auth-svc v0.0.1-rc8/go.mod h1:48c8FsJixnLeWx8F8MDy79FvhU1r0oTU11mwP3JPngQ= +github.com/rarimo/rarime-auth-svc v0.0.1-rc9 h1:JZfq1q3WaaLwa8ICk8RHEx4+ojl/JBE8N5zJ/uHZUwM= +github.com/rarimo/rarime-auth-svc v0.0.1-rc9/go.mod h1:48c8FsJixnLeWx8F8MDy79FvhU1r0oTU11mwP3JPngQ= github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a h1:aqz/1mU+rK/xLqf2/NHu+0fUGbVNf+9DYFI70fQo0M0= github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a/go.mod h1:EYFR6RRqIlnpjcl/SgPgYn8Bmw4+5itRRbPCiSylCds= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= diff --git a/internal/services/api/handlers/middleware.go b/internal/services/api/handlers/middleware.go index cc741f6..c0bfab0 100644 --- a/internal/services/api/handlers/middleware.go +++ b/internal/services/api/handlers/middleware.go @@ -12,20 +12,14 @@ import ( func AuthMiddleware(auth *auth.Client, log *logan.Entry) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - claims, status, err := auth.ValidateJWT(r.Header) + claims, err := auth.ValidateJWT(r.Header) if err != nil { - if status == http.StatusUnauthorized { - ape.Render(w, problems.Unauthorized()) - return - } - log.WithError(err).Error("failed to execute auth validate request") ape.Render(w, problems.InternalError()) return } - ctx := CtxUserClaim(claims)(r.Context()) - next.ServeHTTP(w, r.WithContext(ctx)) + next.ServeHTTP(w, r.WithContext(CtxUserClaim(claims)(r.Context()))) }) } }