diff --git a/assembly/locator.go b/assembly/locator.go index a69b1d5..0e92bd0 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -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), diff --git a/domain/auth.go b/domain/auth.go index d9c5452..94b107a 100644 --- a/domain/auth.go +++ b/domain/auth.go @@ -25,7 +25,7 @@ type UserToken struct { type AuthenticateUserResponse struct { Authenticated bool - ShouldSkip bool + SkipUserAuth bool ErrorReason string AuthData *UserAuthData } diff --git a/middleware/user_authenticate.go b/middleware/user_authenticate.go index 8fab85f..7e03a45 100644 --- a/middleware/user_authenticate.go +++ b/middleware/user_authenticate.go @@ -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) }) } diff --git a/service/user_authentication.go b/service/user_authentication.go index 4a3c22f..3a779b3 100644 --- a/service/user_authentication.go +++ b/service/user_authentication.go @@ -120,7 +120,7 @@ func (s UserAuthentication) Authenticate(ctx *request.Context) (*domain.Authenti } return &domain.AuthenticateUserResponse{ - ShouldSkip: true, + SkipUserAuth: true, }, nil }