From 708a152032278f35846af7a5706295aca096b5d6 Mon Sep 17 00:00:00 2001 From: Dmitry Ponomarev Date: Mon, 17 Jun 2024 13:56:25 +0200 Subject: [PATCH] fix JWT authorizer to use the correct key --- example/api/cmd/api/main.go | 6 ------ pkg/auth/jwt/authorizer.go | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/example/api/cmd/api/main.go b/example/api/cmd/api/main.go index 6eda0ac..4c43e6d 100644 --- a/example/api/cmd/api/main.go +++ b/example/api/cmd/api/main.go @@ -119,12 +119,6 @@ func main() { Logger: loggerObj, JWTProvider: jwtProvider, SessionManager: appinit.SessionManager(conf.Session.CookieName, conf.Session.Lifetime), - // OAuth2provider: oauth2provider, - // AuthOption: gocast.IfThen(conf.IsDebug(), &middleware.AuthOption{ - // DevToken: conf.Session.DevToken, - // DevUserID: conf.Session.DevUserID, - // DevAccountID: conf.Session.DevAccountID, - // }, nil), Authorizers: []auth.Authorizer{ jwt.NewAuthorizer(jwtProvider), oauth2.NewAuthorizer(oauth2provider), diff --git a/pkg/auth/jwt/authorizer.go b/pkg/auth/jwt/authorizer.go index b2500db..54d9cf6 100644 --- a/pkg/auth/jwt/authorizer.go +++ b/pkg/auth/jwt/authorizer.go @@ -29,12 +29,12 @@ func (au *Authorizer) AuthorizerCode() string { } func (au *Authorizer) Authorize(w http.ResponseWriter, r *http.Request) (token string, usr *model.User, acc *model.Account, err error) { - ctx := r.Context() if err = au.jmid.CheckJWT(w, r); err != nil { - ctxlogger.Get(ctx).Debug("JWT authorization", zap.Error(err)) + ctxlogger.Get(r.Context()).Debug("JWT authorization", zap.Error(err)) return "", nil, nil, nil } + ctx := r.Context() jwtToken := ctx.Value(au.jmid.Options.UserProperty) switch t := jwtToken.(type) { case nil: