MSP-6673 check x-application-token at first

This commit is contained in:
komissarovyv committed 2025-11-26 13:39:58 +03:00
1 parent 96f8e79d33
commit 102fa48a92
3 files changed
+17 -6

No files matched your search

+1 -1
View File
@@ -1 +1 @@
5.5.0
5.5.1
+2
View File
@@ -1,3 +1,5 @@
### v5.5.1
* повышен приоритет `x-application-token` над basic-auth, при поиске в запросе токена приложения
### v5.5.0
* Добавлена поддержка basic-auth, где `username` - название приложения, `password` - токен приложения
### v5.4.1
+14 -5
View File
@@ -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
}