Compare commits

...
1 Commits
Author SHA1 Message Date
txix 71a1f0a04e 2026-04-08 18:36:43: merge [main:cca6ce0ad1fef44571b4a61f1aca34f2e41ce5cd];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-04-08 18:36:43 +03:00
5 changed files with 30 additions and 28 deletions

No files matched your search

+1 -1
View File
@@ -1 +1 @@
5.10.0 5.10.1
+2
View File
@@ -1,3 +1,5 @@
### v5.10.1
* Изменен нейминг настройки `customAuth.userAuthSettings.authenticateMethodPath` на `customAuth.userAuthSettings.authenticateEndpoint`
### v5.10.0 ### v5.10.0
* Добавлена конфигурируемая аутентификация/авторизация пользователя * Добавлена конфигурируемая аутентификация/авторизация пользователя
### v5.9.3 ### v5.9.3
+5 -5
View File
@@ -92,9 +92,9 @@ type CookieTokenProvider struct {
} }
type UserAuthSetting struct { type UserAuthSetting struct {
ModuleNameList []string `schema:"Название модулей,для которых настраивается аутентификация/авторизация" validate:"required"` ModuleNameList []string `schema:"Название модулей,для которых настраивается аутентификация/авторизация,название модулей должно быть уникальным" validate:"required"`
TokenProvider string `schema:"Название метода получения токена из запроса" validate:"required"` TokenProvider string `schema:"Название метода получения токена из запроса" validate:"required"`
AuthenticateMethodPath string `schema:"Путь до метода аутентификации,метод вызывается через isp-router-service" validate:"required"` AuthenticateEndpoint string `schema:"Endpoint для аутентификации пользователя,вызывается через isp-router-service" validate:"required"`
CacheDataInSec int `schema:"Время кеширования данных аутентификации/авторизации пользователя,отключен при значениях <=0,в секундах"` CacheDataInSec int `schema:"Время кеширования данных аутентификации/авторизации пользователя,отключен при значениях <=0,в секундах"`
SkipAppAuth bool `schema:"Пропустить аутентификацию и авторизацию приложения"` SkipAppAuth bool `schema:"Пропустить аутентификацию и авторизацию приложения"`
} }
+9 -9
View File
@@ -15,12 +15,12 @@ import (
) )
type UserAuthenticationCache interface { type UserAuthenticationCache interface {
Get(ctx context.Context, authMethodPath string, token string) (*entity.UserAuthData, error) Get(ctx context.Context, authEndpoint string, token string) (*entity.UserAuthData, error)
Set(ctx context.Context, authMethodPath string, token string, data entity.UserAuthData, duration time.Duration) error Set(ctx context.Context, authEndpoint string, token string, data entity.UserAuthData, duration time.Duration) error
} }
type UserAuthenticationRepo interface { type UserAuthenticationRepo interface {
Authenticate(ctx context.Context, methodPath string, token string) (*entity.UserAuthenticateResponse, error) Authenticate(ctx context.Context, authEndpoint string, token string) (*entity.UserAuthenticateResponse, error)
} }
type TokenProvider interface { type TokenProvider interface {
@@ -29,7 +29,7 @@ type TokenProvider interface {
type userAuthSetting struct { type userAuthSetting struct {
tokenProvider string tokenProvider string
authenticatePath string authEndpoint string
authCacheDuration time.Duration authCacheDuration time.Duration
skipAppAuth bool skipAppAuth bool
} }
@@ -82,7 +82,7 @@ func NewUserAuthentication(
} }
settingsByModuleName[moduleName] = userAuthSetting{ settingsByModuleName[moduleName] = userAuthSetting{
tokenProvider: setting.TokenProvider, tokenProvider: setting.TokenProvider,
authenticatePath: setting.AuthenticateMethodPath, authEndpoint: setting.AuthenticateEndpoint,
authCacheDuration: cacheDuration, authCacheDuration: cacheDuration,
skipAppAuth: setting.SkipAppAuth, skipAppAuth: setting.SkipAppAuth,
} }
@@ -141,17 +141,17 @@ func (s UserAuthentication) authenticate(
token string, token string,
) (*domain.AuthenticateUserResponse, error) { ) (*domain.AuthenticateUserResponse, error) {
if setting.authCacheDuration <= 0 { if setting.authCacheDuration <= 0 {
resp, err := s.repo.Authenticate(ctx, setting.authenticatePath, token) resp, err := s.repo.Authenticate(ctx, setting.authEndpoint, token)
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "auth repo authenticate") return nil, errors.WithMessage(err, "auth repo authenticate")
} }
return s.convertAuthReponse(resp, setting.skipAppAuth), nil return s.convertAuthReponse(resp, setting.skipAppAuth), nil
} }
authData, err := s.cache.Get(ctx, setting.authenticatePath, token) authData, err := s.cache.Get(ctx, setting.authEndpoint, token)
switch { switch {
case errors.Is(err, domain.ErrAuthenticationCacheMiss): case errors.Is(err, domain.ErrAuthenticationCacheMiss):
resp, err := s.repo.Authenticate(ctx, setting.authenticatePath, token) resp, err := s.repo.Authenticate(ctx, setting.authEndpoint, token)
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "auth repo authenticate") return nil, errors.WithMessage(err, "auth repo authenticate")
} }
@@ -160,7 +160,7 @@ func (s UserAuthentication) authenticate(
} }
err = s.cache.Set( err = s.cache.Set(
ctx, ctx,
setting.authenticatePath, setting.authEndpoint,
token, token,
*resp.AuthData, *resp.AuthData,
setting.authCacheDuration, setting.authCacheDuration,
+13 -13
View File
@@ -379,14 +379,14 @@ func (s *HappyPathTestSuite) TestUserAuthorization() { // nolint:funlen
}, },
UserAuthSettings: []conf.UserAuthSetting{ UserAuthSettings: []conf.UserAuthSetting{
{ {
ModuleNameList: []string{"target"}, ModuleNameList: []string{"target"},
TokenProvider: "test_provider", TokenProvider: "test_provider",
AuthenticateMethodPath: "test-user-auth/authenticate", AuthenticateEndpoint: "test-user-auth/authenticate",
}, },
{ {
ModuleNameList: []string{"target2"}, ModuleNameList: []string{"target2"},
TokenProvider: "test_provider", TokenProvider: "test_provider",
AuthenticateMethodPath: "failed-user-auth/authenticate", AuthenticateEndpoint: "failed-user-auth/authenticate",
}, },
}, },
} }
@@ -518,15 +518,15 @@ func (s *HappyPathTestSuite) TestUserAuthorization_SkipAppAuth() { // nolint:fun
}, },
UserAuthSettings: []conf.UserAuthSetting{ UserAuthSettings: []conf.UserAuthSetting{
{ {
ModuleNameList: []string{"target"}, ModuleNameList: []string{"target"},
TokenProvider: "test_provider", TokenProvider: "test_provider",
AuthenticateMethodPath: "test-user-auth/authenticate", AuthenticateEndpoint: "test-user-auth/authenticate",
SkipAppAuth: true, SkipAppAuth: true,
}, },
{ {
ModuleNameList: []string{"target2"}, ModuleNameList: []string{"target2"},
TokenProvider: "test_provider", TokenProvider: "test_provider",
AuthenticateMethodPath: "test-user-auth/authenticate", AuthenticateEndpoint: "test-user-auth/authenticate",
}, },
}, },
} }