【问题标题】:decoding Firebase idToken on Google App Engine在 Google App Engine 上解码 Firebase idToken
【发布时间】:2018-05-04 14:30:53
【问题描述】:

我的 firebase 用户正在向我的 API 服务器发送请求。我正在使用 Google Cloud Endpoints 中的安全规则对其进行验证。我在 Google App Engine 上不使用管理 SDK 就提取了他们的用户 ID。

通常,Google 建议通过此代码验证 HTTPS 请求的传入 id 令牌在他们的示例 Firebase Cloud Functions 代码中

  admin.auth().verifyIdToken(idToken).then((decodedIdToken) => {
    console.log('ID Token correctly decoded', decodedIdToken);
    req.user = decodedIdToken;
    return next();
  }).catch((error) => {
    console.error('Error while verifying Firebase ID token:', error);
    res.status(403).send('Unauthorized');
  });

但是,在示例 Google App Engine 代码中,Google 在没有管理 SDK 的情况下解码令牌:

let authUser = { id: 'anonymous' };
const encodedInfo = req.get('X-Endpoint-API-UserInfo');
if (encodedInfo) {
  authUser = JSON.parse(Buffer.from(encodedInfo, 'base64'));
}

我正在使用 Google Cloud Endpoints 来保护托管在 Google App Engine 上的 API。我在云端点上设置了安全性,只允许 firebase 用户访问路由,但是,我只希望用户访问他们自己的数据,所以我需要解码他们的 id 令牌以检索他们的 userID。我想知道 Cloud Endpoints 是否在这里处理身份验证。 我需要让管理员 SDK 验证令牌吗?还是 Google 示例中的简单解码足够安全,因为云端点已经负责验证 idToken?

【问题讨论】:

    标签: google-app-engine firebase-authentication google-cloud-endpoints


    【解决方案1】:

    Admin SDK 正在执行 Endpoints 代理在验证令牌时所做的事情。代理只是传递经过验证的令牌。只要 Endpoints 代理仍在您的应用前面,您就可以解码 X-Endpoint-API-UserInfo 令牌。

    【讨论】:

      猜你喜欢
      • 2012-09-03
      • 2017-05-17
      • 2018-01-14
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 2019-05-17
      • 1970-01-01
      相关资源
      最近更新 更多