2016-04-27 57 views
1

我目前使用電子郵件和密碼登錄。但我希望能夠爲每個用戶分配一個角色:管理員或用戶。我已經讀過,這是通過使用自定義auth方法完成的,但我發現文檔不清晰可以通過電子郵件/密碼認證來實現。如何在Firebase身份驗證中設置角色?

我該怎麼去設置它?

我目前使用火力的餘燼emberfire

更新:

文檔參考:https://www.firebase.com/docs/web/guide/login/custom.html

+0

鏈接添加到文檔您參考嗎?不確定它是Ember還是Ember-Fire或Firebase ..謝謝! – TameBadger

+0

@TameBadger加了它 – FutoRicky

+0

你如何實現它取決於你。自定義安全提供程序是一種方式,但以下是使用任何提供程序的示例:https://gist.github.com/sararob/331760829a9dcb4be3e7。也看到這個2.5歲的答案,仍然非常相關:http://stackoverflow.com/questions/19520615/how-do-i-implement-role-based-access-control-in-firebase –

回答

0

火力地堡上通過ID令牌上的自定義用戶主張的任何用戶的基於角色的訪問剛剛推出支持: https://firebase.google.com/docs/auth/admin/custom-claims

您可以定義管理員訪問規則:

{ 
    "rules": { 
    "adminContent": { 
     ".read": "auth.token.admin === true", 
     ".write": "auth.token.admin === true", 
    } 
    } 
} 

設置與管理SDK用戶角色:

// Set admin privilege on the user corresponding to uid. 
admin.auth().setCustomUserClaims(uid, {admin: true}).then(() => { 
    // The new custom claims will propagate to the user's ID token the 
    // next time a new one is issued. 
}); 

這將傳播到相應的用戶ID令牌聲明。

要從客戶端上的令牌解析它,檢查:https://firebase.google.com/docs/auth/admin/custom-claims#access_custom_claims_on_the_client