我在哪里可以找到包含revokeRefreshTokens方法的firebase-admin包?

时间:2018-01-11 00:59:18

标签: node.js firebase firebase-authentication google-cloud-functions firebase-admin

我需要使用Node.js API文档中描述的revokeRefreshTokens类的Auth方法:https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#revokeRefreshTokens

它包含在我根据https://www.npmjs.com/package/firebase-admin#installation的文档使用npm命令安装的 firebase-admin 包中:

npm install --save firebase-admin

在执行此操作并进入已安装的目录并检查 auth.js 文件时,我发现该方法已丢失。我在哪里可以找到在Firebase云功能中使用的revokeRefreshTokens方法?

最初,我还尝试使用以下方法调用云函数中的方法:

    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp(functions.config().firebase);

    //Some additional code here to fetch the userRecord...

    admin.auth().revokeRefreshTokens(userRecord.uid)
      .then(function() {
        console.log("Successfully revoked token");
      })
      .catch(function(error) {
        console.log("Error revoking token:", error);
      });

错误地说

  

TypeError:admin.auth(...)。revokeRefreshTokens不是函数。

如果需要进一步的信息,请告诉我。

1 个答案:

答案 0 :(得分:1)

确保您安装的是最新版本(5.7.0)。如果您这样做,您将在node_modules/firebase-admin/lib/auth/auth.js(第295行)中找到以下内容:

    /**
     * Revokes all refresh tokens for the specified user identified by the provided UID.
     * In addition to revoking all refresh tokens for a user, all ID tokens issued before
     * revocation will also be revoked on the Auth backend. Any request with an ID token
     * generated before revocation will be rejected with a token expired error.
     *
     * @param {string} uid The user whose tokens are to be revoked.
     * @return {Promise<void>} A promise that resolves when the operation completes
     *     successfully.
     */
    Auth.prototype.revokeRefreshTokens = function (uid) {
        return this.authRequestHandler.revokeRefreshTokens(uid)
            .then(function (existingUid) {
            // Return nothing on success.
        });
    };