Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建Firebase身份验证声明?_Firebase_Spring Security_Firebase Authentication - Fatal编程技术网

如何创建Firebase身份验证声明?

如何创建Firebase身份验证声明?,firebase,spring-security,firebase-authentication,Firebase,Spring Security,Firebase Authentication,我正在开发一个Android应用程序,需要通过服务器应用程序进行身份验证。服务器应用程序是使用Spring Security的Spring引导应用程序。服务器应用程序使用自定义身份验证提供程序为用户设置授予的权限 这是我用来检索idToken的代码: FirebaseToken firebaseToken = null; try { FirebaseApp app = FirebaseUtil.getFirebaseApp(); firebase

我正在开发一个Android应用程序,需要通过服务器应用程序进行身份验证。服务器应用程序是使用Spring Security的Spring引导应用程序。服务器应用程序使用自定义身份验证提供程序为用户设置授予的权限

这是我用来检索idToken的代码:

    FirebaseToken firebaseToken = null;

    try {
        FirebaseApp app = FirebaseUtil.getFirebaseApp();
        firebaseToken = FirebaseAuth.getInstance(app).verifyIdTokenAsync(authenticationToken.getIdToken()).get();
    } catch ( InterruptedException | ExecutionException | CancellationException e ) {
        throw new AuthenticationServiceException(e.getMessage());
    } 

    return firebaseToken; 
如果我有Firebase令牌,我可以检索如下声明:

Map<String, Object> claims = token.getClaims();
Map claims=token.getClaims();
然后,我可以重复这些声明,并创建如下权限:

List<GrantedAuthority> authorities = Lists.newArrayList(); 
authorities.add(new SimpleGrantedAuthority("some_role"));
List authorities=Lists.newArrayList();
添加(新的SimpleGrantedAuthority(“某些角色”);

我不知道如何使用Firebase控制台创建声明。这可能吗?我怀疑我需要使用Firebase数据库,但在Firebase文档中找不到确切的内容。

Firebase身份验证的自定义声明当前只能通过Firebase Admin SDK创建。从:


允许从控制台创建声明也不是一个坏主意,因此我推荐您。

您也可以使用Python轻松地完成此操作,包括:

auth.set_custom_user_claims(user_id, {"admin":True}, app=None)

啊好的。感谢您的回复如果我的答案有用,请单击左侧的向上投票按钮。如果它回答了您的问题,请单击复选标记接受它。这样其他人就知道你得到了(足够的)帮助。看起来自定义声明只能通过javascript创建,这对我来说是不可能的,因为我使用的服务器应用程序是用java开发的。我可以创建自定义令牌,但我想做的是使用现有的身份验证机制之一,最好是电子邮件和密码,并使用JavaSDK添加声明。这似乎是不可能的。Firebase Java Admin SDK正在添加此API。此API不会向客户端公开,因为出于安全原因,在客户端无法设置用户角色。如果您计划添加任意用户字段,最好使用该字段的数据库。PR用于跟踪:
auth.set_custom_user_claims(user_id, {"admin":True}, app=None)