firebase-authentication - 我们为什么不能在Firebase身份验证中使用getUid()与您的后端服务器进行身份验证

标签 firebase-authentication

他们在此代码段(firebase文档)中提到,它们不使用user.getUid()来对您的后端服务器进行身份验证。请改用FirebaseUser.getToken()。

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
    // Name, email address, and profile photo Url
    String name = user.getDisplayName();
    String email = user.getEmail();
    Uri photoUrl = user.getPhotoUrl();

    // The user's ID, unique to the Firebase project. Do NOT use this value to
    // authenticate with your backend server, if you have one. Use
    // FirebaseUser.getToken() instead.
    String uid = user.getUid();
}


getUid()    A unique user ID, intended as the user's unique key across all providers.   
getToken()  The Firebase authentication token for this session.

我的要求是。
  • 首先,我将使用firebase身份验证方法(电子邮件和密码)注册用户。
  • 我将保存字符串uid = user.getUid();注册成功后,在我自己的后端服务器中。
  • 用户信用信息说,用户余额作为关键user.getUid()保存在我自己的后端服务器中。
  • 用户使用电子邮件和密码登录并要求其余额。
  • 我将从firebase中获取user.getUid()并与我的记录进行匹配,如果找到匹配项,则将余额返还给用户。

  • 他们说getUid()是唯一的用户ID,但请勿使用此值向您的后端服务器进行身份验证。

    为什么这样?为什么我们不能使用getUid()对您的后端服务器进行身份验证?

    最佳答案

    uid是用户的唯一标识符。因此,虽然它可以识别用户,但不会对他们进行身份验证。

    一个简单的推论是,我的堆栈溢出ID为209103。知道了这一点,就可以识别出我。但是要向Stack Overflow证明您是Frank Van Puffelen,需要您知道我的证书。

    用户的ID通常会在界面中公开。例如,如果单击我的个人资料,您将看到我的ID。这对于识别我很有必要。如果您还使用相同的ID进行身份验证,则曾经看过您个人资料的每个人都可以在网站上冒充您。关于安全性,这不是一个好主意。

    关于firebase-authentication - 我们为什么不能在Firebase身份验证中使用getUid()与您的后端服务器进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37964425/

    相关文章:

    firebase - Firebase Auth API 能否用于识别在控制台上启用的登录方法

    android - “无法联系 Firebase 服务器”

    android - 在 firebase 应用程序中添加 sha1 失败并出现错误

    javascript - 我如何取消订阅 onAuthStateChanged

    firebase - 在 firebase 规则推送 Id 中添加字符串并检查相等性

    java - 在类中找不到 Social_Security_Number 的 setter /字段

    php - Firebase token 验证

    Firebase 实时数据库 : What's the right security rule for a landing page?

    firebase - 响应中使用 google 'Access-Control-Allow-Credentials' header 的 Flutter Web firebase_auth 登录是 ''(空)

    java - FirebaseAuth 未创建用户