From 9b18fe73512af9c0a698c31d2acac05c57416199 Mon Sep 17 00:00:00 2001 From: txix Date: Wed, 26 Nov 2025 13:43:01 +0300 Subject: [PATCH] 2025-11-26 13:43:01: merge [main:e9c5c9b80517122ca122933c111070bf470e31c1]; --- .version | 2 +- CHANGELOG.md | 2 ++ go.mod | 2 +- go.sum | 4 ++-- middleware/authenticate.go | 19 ++++++++++++++----- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.version b/.version index c7ba1e8..d41f08f 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -5.5.0 \ No newline at end of file +5.5.1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 85279d3..73ea3df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### v5.5.1 +* повышен приоритет `x-application-token` над basic-auth, при поиске в запросе токена приложения ### v5.5.0 * Добавлена поддержка basic-auth, где `username` - название приложения, `password` - токен приложения ### v5.4.1 diff --git a/go.mod b/go.mod index ea72fa5..d32ff77 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/redis/go-redis/v9 v9.11.0 github.com/stretchr/testify v1.11.1 github.com/tomakado/websocketproxy v0.1.0 - github.com/txix-open/isp-kit v1.62.0 + github.com/txix-open/isp-kit v1.63.3 github.com/txix-open/jsonschema v1.3.0 golang.org/x/net v0.44.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 diff --git a/go.sum b/go.sum index 87bae38..b37963d 100644 --- a/go.sum +++ b/go.sum @@ -125,8 +125,8 @@ github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIg github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8= github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM= github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po= -github.com/txix-open/isp-kit v1.62.0 h1:SfY8x5/3yYEicr5phGTJBaUwFvgktSIsD/NubrKYbg4= -github.com/txix-open/isp-kit v1.62.0/go.mod h1:hyCFmWF0qoVY2loTLyHJx8QPZJuULntG0JfthqFCdsA= +github.com/txix-open/isp-kit v1.63.3 h1:UJLgR4z8sYXUX6r1sl6Ww1aijPx6b7ieMeB+elZoViM= +github.com/txix-open/isp-kit v1.63.3/go.mod h1:rwqKqB3PyZxaoep6iH1PKL89LS9nzRklA6+S4II72M4= github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4= github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00= github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0= diff --git a/middleware/authenticate.go b/middleware/authenticate.go index a5c5890..61f8634 100644 --- a/middleware/authenticate.go +++ b/middleware/authenticate.go @@ -4,10 +4,11 @@ import ( "context" "net/http" - "github.com/pkg/errors" "isp-gate-service/domain" "isp-gate-service/httperrors" "isp-gate-service/request" + + "github.com/pkg/errors" ) const ( @@ -61,17 +62,25 @@ func Authenticate(authenticator Authenticator) Middleware { } func extractToken(ctx *request.Context) (string, string, error) { - appName, token, ok := ctx.Request().BasicAuth() - if !ok { - return ctx.Param(applicationTokenHeader), "", nil + var ( + appName string + token string + ok bool + ) + + token = ctx.Param(applicationTokenHeader) + if token != "" { + return token, "", nil } - if appName == "" { + appName, token, ok = ctx.Request().BasicAuth() + if ok && appName == "" { return "", "", httperrors.New( http.StatusUnauthorized, "application name required", errors.New("authenticate: application name required on basic auth"), ) } + return token, appName, nil }