【发布时间】: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