MSP-7470 Add skip app auth log
This commit is contained in:
1 parent
eb6326c343
commit
7cca2eb773
4 files changed
+13
-5
No files matched your search
+1
-1
@@ -132,7 +132,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
||||
),
|
||||
middleware.RequestId(),
|
||||
middleware.ErrorHandler(l.logger),
|
||||
middleware.UserAuthenticate(userAuthentication),
|
||||
middleware.UserAuthenticate(userAuthentication, l.logger),
|
||||
middleware.Authenticate(authentication),
|
||||
middleware.AdminAuthenticate(adminService),
|
||||
middleware.ClientRequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ type UserToken struct {
|
||||
|
||||
type AuthenticateUserResponse struct {
|
||||
Authenticated bool
|
||||
ShouldSkip bool
|
||||
SkipUserAuth bool
|
||||
ErrorReason string
|
||||
AuthData *UserAuthData
|
||||
}
|
||||
|
||||
@@ -8,20 +8,21 @@ import (
|
||||
"isp-gate-service/request"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
)
|
||||
|
||||
type UserAuthenticator interface {
|
||||
Authenticate(ctx *request.Context) (*domain.AuthenticateUserResponse, error)
|
||||
}
|
||||
|
||||
func UserAuthenticate(authenticator UserAuthenticator) Middleware {
|
||||
func UserAuthenticate(authenticator UserAuthenticator, logger log.Logger) Middleware {
|
||||
return func(next Handler) Handler {
|
||||
return HandlerFunc(func(ctx *request.Context) error {
|
||||
resp, err := authenticator.Authenticate(ctx)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "authenticate user: authenticator error")
|
||||
}
|
||||
if resp.ShouldSkip {
|
||||
if resp.SkipUserAuth {
|
||||
return next.Handle(ctx)
|
||||
}
|
||||
|
||||
@@ -34,6 +35,13 @@ func UserAuthenticate(authenticator UserAuthenticator) Middleware {
|
||||
}
|
||||
|
||||
ctx.AuthenticateUser(*resp.AuthData)
|
||||
|
||||
if ctx.SkipAppAuth() {
|
||||
logger.Debug(
|
||||
ctx.Context(),
|
||||
"skip app auth is set. All steps that require app auth data are skipped",
|
||||
)
|
||||
}
|
||||
return next.Handle(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (s UserAuthentication) Authenticate(ctx *request.Context) (*domain.Authenti
|
||||
}
|
||||
|
||||
return &domain.AuthenticateUserResponse{
|
||||
ShouldSkip: true,
|
||||
SkipUserAuth: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user