2016-08-29 34 views
3

我有一個(我希望)關於Keystone授權的快速問題:它似乎是「用戶」對象是框架中的核心依賴項。我想完全支持它,但似乎沒有辦法讓應用程序沒有它。是否可以在沒有keystone用戶模型的情況下在keystone.js中使用自定義驗證?

我在這裏運行基本旁路:

keystone.init({ 
    //... 
    'auth': (req, res, next)=>{ 
     if(Roles.has(Roles.Admin, Roles.Keyston)){ 
     next(); 
     } else { 
     throw "403"; //Terminate 
     } 
    }, 
    'user model': 'User', 
    //... 
}) 

,這導致:

Sorry, an error occurred loading the page (500) 

snip\KS2\node_modules\keystone\templates\layout\base.jade:80 
> 79| a(href='/keystone/' + User.path + '/' + user.id)= User.getDocumentName(user) 
80| | . 
81| 
82| //- Common 

item.get is not a function 

結果,預計用戶對象上存在要求(即使我使用我自己的身份驗證方法)。如果我完全禁用身份驗證,看起來很好,我可以使用一些中間件來保護路由,但這看起來像是相當有問題的行爲。

「用戶」對象實際上是框架中的依賴項,還是基本上是爲了方便?卸下模型

//'user model' : 'User' 

崩潰梯形

Sorry, an error occurred loading the page (500) Unknown keystone list undefined). 

我相當肯定前者錯誤與上請求的「用戶對象」設定爲一些愚蠢的,因此玉模板炸燬。是否有可能將此用戶對象與框架分離?如果不是可以設置此對象,以便我可以繼續使用passport.js進行主身份驗證?

我對這個主題特別感興趣,因爲我想在Keystone.js管理模塊中實現基於角色的身份驗證,並且沒有關於如何工作的更多信息/解決方案的想法我沒有跳點。

(**編輯即使有權威性組存在虛假錯誤)

Sorry, an error occurred loading the page (500) 

...snip\KS2\node_modules\keystone\templates\layout\base.jade:78 
76| if User && user 
77| | Signed in as 
> 78| a(href='/keystone/' + User.path + '/' + user.id)= User.getDocumentName(user) 
79| | . 
80| 
81| //- Common 

item.get is not a function 

退出甚至auth: false因爲我有一個轉動起來空,崩潰模板中的「用戶」對象。

編輯#2 我已經創建了一個解決崩潰時用戶身份驗證是關閉的,它並沒有真正回答這個問題,但它使可用的應用程序再次而不依賴於Keystone.js一個補丁認證(這是該CMS的關鍵要求)。

回答

3

我仍然在尋找這方面的幫助,但這裏是我如何繞過它暫時。看起來應用程序正朝着管理控制檯的全新方向發展。

我發出一個針對該叉的拉請求(我相信它是當前npm上的包)。

您可以查看我的叉子在這裏: https://github.com/danielbchapman/keystone/commit/d28dae031252fc2512598ef8496f336f27c1bbc0

Git的修補程序標籤v3.22 從d28dae031252fc2512598ef8496f336f27c1bbc0 //週一09月17日00:00:00 2001年 來源:「丹尼爾B.查普曼」 日期:星期二,2016年8月30日9點25分五十秒-0600 主題:[PATCH]增加的局部auth變量,反映了 keystone.get('auth')配置設置,使得使用 自定義用戶對象(如Passport.js應用)不會觸發在 期行政頁面崩潰,由於「簽署爲」功能。

--- 
lib/core/render.js   | 1 + 
templates/layout/base.jade | 2 +- 
2 files changed, 2 insertions(+), 1 deletion(-) 

diff --git a/lib/core/render.js b/lib/core/render.js 
index 5d80453..2b03b7f 100644 
--- a/lib/core/render.js 
+++ b/lib/core/render.js 
@@ -59,6 +59,7 @@ function render(req, res, view, ext) { 
     moment: moment, 
     numeral: numeral, 
     env: keystone.get('env'), 
+  auth: keystone.get('auth'), 
     brand: keystone.get('brand'), 
     appversion : keystone.get('appversion'), 
     nav: keystone.nav, 
diff --git a/templates/layout/base.jade b/templates/layout/base.jade 
index 1caee5e..95639c6 100644 
--- a/templates/layout/base.jade 
+++ b/templates/layout/base.jade 
@@ -73,7 +73,7 @@ html 
     #footer: .container 
      p #{brand} #{appversion} 
       | Powered by <a href="http://keystonejs.com" target="_blank">KeystoneJS</a> version #{version}. 
-    if User && user 
+    if User && user && auth 
        | Signed in as 
        a(href='/keystone/' + User.path + '/' + user.id)= User.getDocumentName(user) 
        | . 
-- 
1.9.5.msysgit.0 
+1

的說明(這是最近上投)這個補丁是由團隊拒絕,所以應該被歸類作爲黑客,我會把git-repository放在任何需要它的人身上。 –

相關問題