MSP-6673 check x-application-token at first
This commit is contained in:
1 parent
96f8e79d33
commit
102fa48a92
3 files changed
+17
-6
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v5.5.1
|
||||
* повышен приоритет `x-application-token` над basic-auth, при поиске в запросе токена приложения
|
||||
### v5.5.0
|
||||
* Добавлена поддержка basic-auth, где `username` - название приложения, `password` - токен приложения
|
||||
### v5.4.1
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user