2016-04-27 28 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