From 7f708b3a2d656582ed136361b805fe0da20b77df Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 6 Jul 2023 12:13:45 +0300 Subject: [PATCH] [#111] auth: Get log from real request context Signed-off-by: Denis Kirillov --- api/user_auth.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api/user_auth.go b/api/user_auth.go index 0bfb4fd2d..94ba2e659 100644 --- a/api/user_auth.go +++ b/api/user_auth.go @@ -26,12 +26,11 @@ var ClientTime = KeyWrapper("__context_client_time") func AuthMiddleware(log *zap.Logger, center auth.Center) mux.MiddlewareFunc { return func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var ctx context.Context + ctx := r.Context() box, err := center.Authenticate(r) if err != nil { if err == auth.ErrNoAuthorizationHeader { reqLogOrDefault(ctx, log).Debug("couldn't receive access box for gate key, random key will be used") - ctx = r.Context() } else { reqLogOrDefault(ctx, log).Error("failed to pass authentication", zap.Error(err)) if _, ok := err.(errors.Error); !ok { @@ -41,7 +40,7 @@ func AuthMiddleware(log *zap.Logger, center auth.Center) mux.MiddlewareFunc { return } } else { - ctx = context.WithValue(r.Context(), BoxData, box.AccessBox) + ctx = context.WithValue(ctx, BoxData, box.AccessBox) if !box.ClientTime.IsZero() { ctx = context.WithValue(ctx, ClientTime, box.ClientTime) }