简体   繁体   English

Firebase数据库身份验证电话权限被拒绝

[英]Firebase database Authentication phone Permission denied

I'm try to write app and i have some security issue that I cant solve and I need help. 我正在尝试编写应用程序,但遇到一些无法解决的安全问题,需要帮助。 I'm using user phone authentication on firebase and it's working ok. 我在Firebase上使用了用户电话身份验证,并且工作正常。 Now I wants when user auth is granted the user id save on database and it's working . 现在我想在授予用户身份验证后将用户ID保存在数据库中,并且该数据库正在运行。

But the problem is the rules I use this code for write on database for new user: 但是问题是我使用以下代码在新用户的数据库上写入的规则:

{
  "rules": {

      ".write": "auth == null ",
      ".read": "auth == null "              
  }
}

this code is for when new user register: 此代码适用于新用户注册时:

  FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
   Firebase Ref = new Firebase( "database address" );
     Firebase usersRef = Ref.child( "Users" ).child( "user_id" );
       usersRef.setValue( user.getUid() );

when i use this rule Authentication denied : 当我使用此规则身份验证被拒绝时:

{
  "rules": {

      ".write": "auth != null ",
      ".read": "auth != null "              
  }
}

but my user already is registered and i get his id and phone form Authentication user how can i solve this security issue ? 但是我的用户已经注册,并且我获得了他的ID和电话表格身份验证用户如何解决此安全问题?

D/FirebaseAuth: Notifying id token listeners about user ( b3bizXzmH7XQfXWNvHCMVXzDHSx2 ).
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 0 auth state listeners.
D/PhoneAuthActivity: signInWithCredential:success
D/FirebaseAuth: Notifying id token listeners about user ( b3bizXzmH7XQfXWNvHCMVXzDHSx2 ).
D/FirebaseApp: Notifying auth state listeners.
               Notified 0 auth state listeners.
D/PhoneAuthActivity: signInWithCredential:success
W/RepoOperation: setValue at /Users/user_id failed: FirebaseError: Permission denied
W/RepoOperation: setValue at /Users/user_id failed: FirebaseError: Permission denied
D/FirebaseAuth: Notifying id token listeners about user ( b3bizXzmH7XQfXWNvHCMVXzDHSx2 ).
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 0 auth state listeners.
D/PhoneAuthActivity: signInWithCredential:success
W/RepoOperation: setValue at /Users/user_id failed: FirebaseError: Permission denied

try 尝试

{
"rules": {

  ".write": "auth == true",
  ".read": "auth == true"              
 }
}

I solved my problem the answer: 我解决了我的问题的答案:

   FirebaseUser user = task.getResult().getUser();
          mDatabase =FirebaseDatabase.getInstance().getReference();
                 String current_uid =user.getUid();
                mDatabase.child( "Users" ).child( "uid" ).setValue( current_uid );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM