使用Firebase Admin SDK吊销刷新令牌所需的凭证实现是什么

时间:2019-02-27 05:49:44

标签: firebase firebase-authentication google-cloud-functions firebase-admin google-iam

问题:

使用Firebase Admin SDK撤销刷新令牌所需的凭据实现是什么


场景

我有一个执行以下代码的云函数:

CloudFunctionCode:

const admin = require('firebase-admin')
try { admin.initializeApp() } catch (e) { console.log(e) }

//...Irrelevant code in between...

function getRevokeRefreshTokens(request, response) {
  try { admin.initializeApp() } catch (e) { console.log(e) }
  admin.auth().revokeRefreshTokens('Oe4IXqqZj1b1fsfPYFjft0tebs11')
    .then(() => {
      return admin.auth().getUser('Oe4IXqqZj1b1fsfPYFjft0tebs11');
    })
    .then((userRecord) => {
      return new Date(userRecord.tokensValidAfterTime).getTime() / 1000;
    })
    .then((timestamp) => {
      console.log("Tokens revoked at: ", timestamp);
      return response.status(200).send(
        "Tokens revoked at: ", timestamp
      )
  });
}

云功能记录错误:

Error: Credential implementation provided to initializeApp() via the "credential" property has insufficient permission to access the requested resource. See https://firebase.google.com/docs/admin/setup for details on how to authenticate this SDK with appropriate permissions.
    at FirebaseAuthError.Error (native)
    at FirebaseAuthError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at FirebaseAuthError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
    at new FirebaseAuthError (/user_code/node_modules/firebase-admin/lib/utils/error.js:143:16)
    at Function.FirebaseAuthError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:182:16)
    at /user_code/node_modules/firebase-admin/lib/auth/auth-api-request.js:818:49
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

具有以下角色的IAM当前成员:

enter image description here

在阅读有关如何撤消刷新令牌的Manage User Sessions文档之后,我无法确切找到firebase-admin所需的凭据,以便可以撤消刷新令牌。

0 个答案:

没有答案