警告:不要相信這個答案。就在這裏討論。
tldr:我不認爲這是可能的,沒有運行自己的服務器。
這是我嘗試迄今:
{
"rules": {
".read": "auth.provider === 'google' && root.child('users').child(auth.uid).child('email').val().endsWith('@foobar.com')",
".write": "auth.provider === 'google' && root.child('users').child(auth.uid).child('email').val().endsWith('@foobar.com')",
"users": {
"$user_id": {
".write": "auth.provider === 'google' && $user_id === auth.uid && newData.child('email').val().endsWith('@foobar.com')"
}
}
}
}
我相信上面的說「只有讓人們創建一個新用戶,如果他們通過谷歌認證,正在努力編寫成themselve數據庫節點($user_id === auth.uid
)和他們的電子郵件在foobar.com結束「。
但是,有一個問題被指出:任何Web客戶端都可以在將消息發送到Firebase之前輕鬆更改其電子郵件(使用開發控制檯)。因此,我們無法信任存儲在Firebase中的用戶條目的數據。
我認爲我們唯一可以信任的是規則中的auth
對象。那個auth
對象由Firebase的後端填充。而且,不幸的是,auth
對象不包含電子郵件地址。
爲了記錄在案,我將我的用戶是這樣的:
function authDataCallback(authData) {
if (authData) {
console.log("User " + authData.uid + " is logged in with " + authData.provider + " and has displayName " + authData.google.displayName);
// save the user's profile into the database so we can list users,
// use them in Security and Firebase Rules, and show profiles
ref.child("users").child(authData.uid).set({
provider: authData.provider,
name: getName(authData),
email: authData.google.email
});
正如你也許能夠想象,一個確定的用戶可以(通過使用DevTools,爲例子)覆蓋的email
這裏的價值。
問題:當你說從一個域鎖定,這是否意味着鎖定到一個單一的供應商,像谷歌和它的字面意思是隻允許從myDomain的用戶訪問您的火力地堡即測試@ myDomain的認證通過密碼是好的,但不允許通過谷歌認證的事物@另一個域名。 – Jay
我的意思是,「來自@ foobar.com的任何人,經Google驗證/認證,都可以讀取和寫入數據庫」 –
您是否確實需要規則?在某些時候,用戶必須輸入他們的電子郵件地址以便能夠登錄或創建他們的帳戶,所以您不能在輸入時解析它,並拒絕任何沒有@ foobar.com的帳戶作爲域名? – Jay