【问题标题】:Where can I find the firebase-admin package which contains the revokeRefreshTokens method?在哪里可以找到包含 revokeRefreshTokens 方法的 firebase-admin 包?
【发布时间】:2018-06-20 06:31:24
【问题描述】:

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

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

npm install --save firebase-admin

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

最初,我还尝试使用以下方法在我的 Cloud Function 中调用该方法:

    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 不是函数。

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

【问题讨论】:

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


    【解决方案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.
            });
        };
    

    【讨论】:

    • 感谢@Hiranya,它成功了!此外,我还必须在我的 Firebase Cloud Functions 安装的 functions 目录下的 package.json 文件中指定此包的更新版本。
    猜你喜欢
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 2020-04-28
    • 2019-09-13
    • 2014-02-06
    相关资源
    最近更新 更多