2013-10-28 27 views
2

我正在使用Firebase作爲後端的應用程序。我有一個使用Firebase的GitHub身份驗證工作實現。但是,我想將完整的應用程序(所有讀/寫操作)限制在特定GitHub組織中的人員。通過Firebase中的Github組織限制登錄

從我收集的內容來看,這是通過在Forge中添加安全規則來完成的。但是,用戶的組織不屬於GitHub提供給Firebase使用的「基本身份驗證數據」。我有沒有辦法讓應用程序僅供特定組織的成員使用?

目前代碼:

var FB = new Firebase('https://XXXXX.firebaseio.com'); 
var auth = new FirebaseSimpleLogin(FB, function(error, user){ 
    if(user==null){ 
    auth.login('github',{rememberMe:true}); 
    } 
    else{ 
    //We are logged in 
    $.getJSON("https://api.github.com/user/orgs?access_token="+user.accessToken+"&callback=?", function(data){ 
     var orgs = data.data.map(function(org){return org.login}); 
     if(orgs.indexOf(config.github_org)>-1){ 
     //Public Member of Chosen Github Org 
     //Now we fetch the data and render it 
     } 
     else{ 
     //Throw them out 
     alert("Join the group "+config.github_org+" on GitHub to get access to Eon"); 
     document.location="https://github.com/"+config.github_org; 
     } 
    }) 
    } 
}); 

回答

1

要使用FB安全規則,你需要將auth數據與火力地堡的東西(如組織名單)比較,但是它看起來像你試圖讓那些在每一次飛行。相反,我建議你保持由他們auth.uid組織具有組織列出了可以覈對在你的火力地堡users集合:

users 
    uid1 
    ... 
    uidX 
    orgs 
     org1 
     ... 
     orgX 

因此,當一個用戶試圖訪問一個給定的orgX你可以檢查,看看是否root.child('users').child(auth.uid).child('orgs/orgX')存在於您的安全規則中。