From a71907fd8e32e883ec739d4e9618b7c7bc8acf90 Mon Sep 17 00:00:00 2001 From: Umputun Date: Wed, 12 Sep 2018 00:28:00 -0500 Subject: [PATCH] reduce frome AdminStore to KeyStore in Authenticator --- backend/app/rest/auth/auth.go | 12 ++++++++---- backend/app/rest/auth/auth_test.go | 2 +- backend/app/rest/auth/jwt.go | 5 ----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/backend/app/rest/auth/auth.go b/backend/app/rest/auth/auth.go index 758924ab..98cbc72f 100644 --- a/backend/app/rest/auth/auth.go +++ b/backend/app/rest/auth/auth.go @@ -9,18 +9,22 @@ import ( "github.com/umputun/remark/backend/app/rest" "github.com/umputun/remark/backend/app/store" - "github.com/umputun/remark/backend/app/store/admin" ) // Authenticator is top level auth object providing middlewares type Authenticator struct { JWTService *JWT Providers []Provider - AdminStore admin.Store + KeysStore KeyStore DevPasswd string PermissionChecker PermissionChecker } +// KeyStore defines sub-interface for consumers needed just a key +type KeyStore interface { + Key(siteID string) (key string, err error) +} + var devUser = store.User{ ID: "dev", Name: "developer one", @@ -112,14 +116,14 @@ func (a *Authenticator) Auth(reqAuth bool) func(http.Handler) http.Handler { } func (a *Authenticator) checkSecretKey(r *http.Request) bool { - if a.AdminStore == nil { + if a.KeysStore == nil { return false } siteID := r.URL.Query().Get("site") secret := r.URL.Query().Get("secret") - skey, err := a.AdminStore.Key(siteID) + skey, err := a.KeysStore.Key(siteID) if err != nil { return false } diff --git a/backend/app/rest/auth/auth_test.go b/backend/app/rest/auth/auth_test.go index c69df4d9..5350bc10 100644 --- a/backend/app/rest/auth/auth_test.go +++ b/backend/app/rest/auth/auth_test.go @@ -223,7 +223,7 @@ func TestAdminRequired(t *testing.T) { } func TestAuthWithSecret(t *testing.T) { - a := Authenticator{DevPasswd: "123456", AdminStore: admin.NewStaticKeyStore("secretkey")} + a := Authenticator{DevPasswd: "123456", KeysStore: admin.NewStaticKeyStore("secretkey")} router := chi.NewRouter() router.With(a.Auth(true), a.AdminOnly).Get("/auth", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(201) diff --git a/backend/app/rest/auth/jwt.go b/backend/app/rest/auth/jwt.go index a95f2934..0326ce48 100644 --- a/backend/app/rest/auth/jwt.go +++ b/backend/app/rest/auth/jwt.go @@ -42,11 +42,6 @@ const jwtHeaderKey = "X-JWT" const xsrfCookieName = "XSRF-TOKEN" const xsrfHeaderKey = "X-XSRF-TOKEN" -// KeyStore defines sub-interface for consumers needed just a key -type KeyStore interface { - Key(siteID string) (key string, err error) -} - // NewJWT makes JWT service func NewJWT(keyStore KeyStore, secureCookies bool, tokenDuration time.Duration, cookieDuration time.Duration) *JWT { res := JWT{