代码之家  ›  专栏  ›  技术社区  ›  Teoman shipahi

如何在创建Firebase帐户时使用生成的accessToken?

  •  0
  • Teoman shipahi  · 技术社区  · 7 年前

    在我用下面的电子邮件和密码创建用户之后,

    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      // ...
    });
    

    firebase返回我创建的用户对象,如下所示:

    {
      "uid": "huuX6OwdbfNvthORiDzNV6seo3D3",
      "displayName": null,
      "photoURL": null,
      "email": "qqq2@yahoo.com",
      "emailVerified": false,
      "phoneNumber": null,
      "isAnonymous": false,
      "providerData": [
        {
          "uid": "qqq2@yahoo.com",
          "displayName": null,
          "photoURL": null,
          "email": "qqq2@yahoo.com",
          "phoneNumber": null,
          "providerId": "password"
        }
      ],
      "apiKey": "qqqwwweee",
      "appName": "[DEFAULT]",
      "authDomain": null,
      "stsTokenManager": {
        "apiKey": "qqqwwweee",
        "refreshToken": "AGdpqewb4UYbr5Uo5",
        "accessToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImI4OWY",
        "expirationTime": 1532487232918
      },
      "redirectEventId": null,
      "lastLoginAt": "1532483591000",
      "createdAt": "1532482346000"
    }
    

    signInWithEmailAndPassword 方法生成新的 accessToken refreshToken

    但我想用 访问令牌

    以及为此提供的方法?

    1 回复  |  直到 7 年前
        1
  •  0
  •   bojeil    6 年前

    您正在访问用户的内部。这些可以更改。您应该依赖正式文档化的API。 accessToken 基本上是Firebase ID令牌的内部名称。正确的方法是打电话 user.getIdToken()