Skip to content

Commit

Permalink
refactor validate jwt pkg method
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Mar 11, 2024
1 parent 1169615 commit de1e225
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 4 additions & 0 deletions internal/cookies/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/rarimo/auth-svc/internal/jwt"
)

const (
CookieHeaderName = "Cookie"
)

type Cookies struct {
Domain string
Secure bool
Expand Down
12 changes: 4 additions & 8 deletions pkg/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down

0 comments on commit de1e225

Please sign in to comment.