From de1e2258f175b76f564246e171a180ea2283a01d Mon Sep 17 00:00:00 2001 From: olegfomenko Date: Mon, 11 Mar 2024 16:33:12 +0200 Subject: [PATCH] refactor validate jwt pkg method --- internal/cookies/main.go | 4 ++++ pkg/auth/client.go | 12 ++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/cookies/main.go b/internal/cookies/main.go index 0641d6a..1257809 100644 --- a/internal/cookies/main.go +++ b/internal/cookies/main.go @@ -7,6 +7,10 @@ import ( "github.com/rarimo/auth-svc/internal/jwt" ) +const ( + CookieHeaderName = "Cookie" +) + type Cookies struct { Domain string Secure bool diff --git a/pkg/auth/client.go b/pkg/auth/client.go index 133400d..a7f9856 100644 --- a/pkg/auth/client.go +++ b/pkg/auth/client.go @@ -3,10 +3,10 @@ package auth import ( "encoding/json" "fmt" + "github.com/rarimo/auth-svc/internal/cookies" + "github.com/rarimo/auth-svc/internal/jwt" "net/http" - "github.com/rarimo/auth-svc/internal/jwt" - "github.com/rarimo/auth-svc/pkg" "github.com/rarimo/auth-svc/resources" "gitlab.com/distributed_lab/logan/v3/errors" ) @@ -21,17 +21,13 @@ type Client struct { } func (a *Client) ValidateJWT(r *http.Request) (claims []resources.Claim, err error) { - token, err := pkg.GetToken(r, jwt.AccessTokenType) - if err != nil { - return nil, err - } - req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", a.Addr, FullValidatePath), nil) if err != nil { return nil, errors.Wrap(err, "failed to create request") } - pkg.SetBearer(req, token) + req.Header.Set(jwt.AuthorizationHeaderName, r.Header.Get(jwt.AuthorizationHeaderName)) + req.Header.Set(cookies.CookieHeaderName, r.Header.Get(cookies.CookieHeaderName)) resp, err := a.Do(req) if err != nil {