MSP-7470 AuthMethodBasePath -> AuthenticateMethodPath
This commit is contained in:
1 parent
215ccbd25b
commit
1b0651e42f
5 files changed
+32
-34
No files matched your search
+5
-5
@@ -92,9 +92,9 @@ type CookieTokenProvider struct {
|
||||
}
|
||||
|
||||
type UserAuthSetting struct {
|
||||
ModuleNameList []string `schema:"Название модулей,для которых настраивается аутентификация/авторизация" validate:"required"`
|
||||
TokenProvider string `schema:"Название метода получения токена из запроса" validate:"required"`
|
||||
AuthMethodBasePath string `schema:"Путь до метода аутентификации/авторизации,метод вызывается через isp-router-service" validate:"required"`
|
||||
CacheDataInSec int `schema:"Время кеширования данных авторизации пользователя,отключен при значениях <=0,в секундах"`
|
||||
SkipAppAuth bool `schema:"Пропустить аутентификацию и авторизацию приложения"`
|
||||
ModuleNameList []string `schema:"Название модулей,для которых настраивается аутентификация/авторизация" validate:"required"`
|
||||
TokenProvider string `schema:"Название метода получения токена из запроса" validate:"required"`
|
||||
AuthenticateMethodPath string `schema:"Путь до метода аутентификации,метод вызывается через isp-router-service" validate:"required"`
|
||||
CacheDataInSec int `schema:"Время кеширования данных аутентификации/авторизации пользователя,отключен при значениях <=0,в секундах"`
|
||||
SkipAppAuth bool `schema:"Пропустить аутентификацию и авторизацию приложения"`
|
||||
}
|
||||
@@ -26,11 +26,9 @@ func NewUserAuth(lb *lb.RoundRobin) UserAuth {
|
||||
|
||||
func (r UserAuth) Authenticate(
|
||||
ctx context.Context,
|
||||
authModuleName string,
|
||||
method string,
|
||||
token string,
|
||||
) (*entity.UserAuthenticateResponse, error) {
|
||||
method := fmt.Sprintf("%s/authenticate", authModuleName)
|
||||
|
||||
ctx = http_metrics.ClientEndpointToContext(ctx, method)
|
||||
|
||||
host, err := r.lb.Next()
|
||||
|
||||
@@ -27,8 +27,8 @@ func NewUserAuthenticationCache(cache Cache) UserAuthenticationCache {
|
||||
}
|
||||
}
|
||||
|
||||
func (r UserAuthenticationCache) Get(ctx context.Context, authModuleName string, token string) (*entity.UserAuthData, error) {
|
||||
data, ok := r.cache.Get(r.key(authModuleName, token))
|
||||
func (r UserAuthenticationCache) Get(ctx context.Context, authMethodPath string, token string) (*entity.UserAuthData, error) {
|
||||
data, ok := r.cache.Get(r.key(authMethodPath, token))
|
||||
if !ok {
|
||||
return nil, domain.ErrAuthenticationCacheMiss
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (r UserAuthenticationCache) Get(ctx context.Context, authModuleName string,
|
||||
|
||||
func (r UserAuthenticationCache) Set(
|
||||
ctx context.Context,
|
||||
authModuleName string,
|
||||
authMethodPath string,
|
||||
token string,
|
||||
data entity.UserAuthData,
|
||||
duration time.Duration,
|
||||
@@ -54,7 +54,7 @@ func (r UserAuthenticationCache) Set(
|
||||
return errors.WithMessage(err, "json marshal auth data")
|
||||
}
|
||||
|
||||
r.cache.Set(r.key(authModuleName, token), value, duration)
|
||||
r.cache.Set(r.key(authMethodPath, token), value, duration)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ import (
|
||||
)
|
||||
|
||||
type UserAuthenticationCache interface {
|
||||
Get(ctx context.Context, authBasePath string, token string) (*entity.UserAuthData, error)
|
||||
Set(ctx context.Context, authBasePath string, token string, data entity.UserAuthData, duration time.Duration) error
|
||||
Get(ctx context.Context, authMethodPath string, token string) (*entity.UserAuthData, error)
|
||||
Set(ctx context.Context, authMethodPath string, token string, data entity.UserAuthData, duration time.Duration) error
|
||||
}
|
||||
|
||||
type UserAuthenticationRepo interface {
|
||||
Authenticate(ctx context.Context, authModuleName string, token string) (*entity.UserAuthenticateResponse, error)
|
||||
Authenticate(ctx context.Context, methodPath string, token string) (*entity.UserAuthenticateResponse, error)
|
||||
}
|
||||
|
||||
type TokenProvider interface {
|
||||
@@ -29,7 +29,7 @@ type TokenProvider interface {
|
||||
|
||||
type userAuthSetting struct {
|
||||
tokenProvider string
|
||||
authBasePath string
|
||||
authenticatePath string
|
||||
authCacheDuration time.Duration
|
||||
skipAppAuth bool
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func NewUserAuthentication(
|
||||
}
|
||||
settingsByModuleName[moduleName] = userAuthSetting{
|
||||
tokenProvider: setting.TokenProvider,
|
||||
authBasePath: setting.AuthMethodBasePath,
|
||||
authenticatePath: setting.AuthenticateMethodPath,
|
||||
authCacheDuration: cacheDuration,
|
||||
skipAppAuth: setting.SkipAppAuth,
|
||||
}
|
||||
@@ -141,17 +141,17 @@ func (s UserAuthentication) authenticate(
|
||||
token string,
|
||||
) (*domain.AuthenticateUserResponse, error) {
|
||||
if setting.authCacheDuration <= 0 {
|
||||
resp, err := s.repo.Authenticate(ctx, setting.authBasePath, token)
|
||||
resp, err := s.repo.Authenticate(ctx, setting.authenticatePath, token)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "auth repo authenticate")
|
||||
}
|
||||
return s.convertAuthReponse(resp, setting.skipAppAuth), nil
|
||||
}
|
||||
|
||||
authData, err := s.cache.Get(ctx, setting.authBasePath, token)
|
||||
authData, err := s.cache.Get(ctx, setting.authenticatePath, token)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrAuthenticationCacheMiss):
|
||||
resp, err := s.repo.Authenticate(ctx, setting.authBasePath, token)
|
||||
resp, err := s.repo.Authenticate(ctx, setting.authenticatePath, token)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "auth repo authenticate")
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func (s UserAuthentication) authenticate(
|
||||
}
|
||||
err = s.cache.Set(
|
||||
ctx,
|
||||
setting.authBasePath,
|
||||
setting.authenticatePath,
|
||||
token,
|
||||
*resp.AuthData,
|
||||
setting.authCacheDuration,
|
||||
|
||||
+13
-13
@@ -379,14 +379,14 @@ func (s *HappyPathTestSuite) TestUserAuthorization() { // nolint:funlen
|
||||
},
|
||||
UserAuthSettings: []conf.UserAuthSetting{
|
||||
{
|
||||
ModuleNameList: []string{"target"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthMethodBasePath: "test-user-auth",
|
||||
ModuleNameList: []string{"target"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthenticateMethodPath: "test-user-auth/authenticate",
|
||||
},
|
||||
{
|
||||
ModuleNameList: []string{"target2"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthMethodBasePath: "failed-user-auth",
|
||||
ModuleNameList: []string{"target2"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthenticateMethodPath: "failed-user-auth/authenticate",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -518,15 +518,15 @@ func (s *HappyPathTestSuite) TestUserAuthorization_SkipAppAuth() { // nolint:fun
|
||||
},
|
||||
UserAuthSettings: []conf.UserAuthSetting{
|
||||
{
|
||||
ModuleNameList: []string{"target"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthMethodBasePath: "test-user-auth",
|
||||
SkipAppAuth: true,
|
||||
ModuleNameList: []string{"target"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthenticateMethodPath: "test-user-auth/authenticate",
|
||||
SkipAppAuth: true,
|
||||
},
|
||||
{
|
||||
ModuleNameList: []string{"target2"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthMethodBasePath: "test-user-auth",
|
||||
ModuleNameList: []string{"target2"},
|
||||
TokenProvider: "test_provider",
|
||||
AuthenticateMethodPath: "test-user-auth/authenticate",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user