在 Google App Engine NodeJS 服务器上验证用户请求的 Firebase 身份验证令牌?
Verify the Firebase authentication token of a user's request on an Google App Engine NodeJS server?
所以我在 how to integrate Firebase authentication with Google App Engine 上找到了这篇文档,但它是为 Python 编写的,它看起来很旧,因为我在代码中发现了一些不一致之处。没有找到NodeJS的对应教程
据我了解,流程的顺序应该是这样的:
第 1 步
- 用户通过客户端代码(firebase JS SDK)登录,我使用
user.getIdToken()
获取其 JWT userIdToken
第 2 步
- 使用以下 header 获取我的 GAE 服务器 URL:
headers: {
'Authorization': 'Bearer ' + userIdToken
}
然后教程指示我应该使用 Google Auth 库,以验证 JWT userIdToken
。
Before the client can access server data, your server must verify the token is signed by Firebase. You can verify this token using the Google Authentication Library for Python. Use the authentication library's verify_firebase_token
function to verify the bearer token and extract the claims:
因此,对于 NodeJS 服务器,我应该使用以下库,对吗?
或者,我可以使用 firebase-admin
来验证 userIdToken
,如以下文档所示?
https://firebase.google.com/docs/auth/admin/verify-id-tokens
我想 firebase-admin
似乎是处理这种情况的方法。但是,如果我选择那条路径,我是否仍应使用 'Authorization': 'Bearer '
header 传递令牌?或者有更好的处理方法吗?
您可以通过任何方式将 ID 令牌传递到您的后端。正如您在文档中看到的那样,使用授权 header 是惯例和标准,但不是必需的。代码示例应该清楚地表明您真正需要的是传递该令牌以使用 Firebase Admin SDK 进行验证。
所以我在 how to integrate Firebase authentication with Google App Engine 上找到了这篇文档,但它是为 Python 编写的,它看起来很旧,因为我在代码中发现了一些不一致之处。没有找到NodeJS的对应教程
据我了解,流程的顺序应该是这样的:
第 1 步
- 用户通过客户端代码(firebase JS SDK)登录,我使用
user.getIdToken()
获取其 JWT
userIdToken
第 2 步
- 使用以下 header 获取我的 GAE 服务器 URL:
headers: {
'Authorization': 'Bearer ' + userIdToken
}
然后教程指示我应该使用 Google Auth 库,以验证 JWT userIdToken
。
Before the client can access server data, your server must verify the token is signed by Firebase. You can verify this token using the Google Authentication Library for Python. Use the authentication library's
verify_firebase_token
function to verify the bearer token and extract the claims:
因此,对于 NodeJS 服务器,我应该使用以下库,对吗?
或者,我可以使用 firebase-admin
来验证 userIdToken
,如以下文档所示?
https://firebase.google.com/docs/auth/admin/verify-id-tokens
我想 firebase-admin
似乎是处理这种情况的方法。但是,如果我选择那条路径,我是否仍应使用 'Authorization': 'Bearer '
header 传递令牌?或者有更好的处理方法吗?
您可以通过任何方式将 ID 令牌传递到您的后端。正如您在文档中看到的那样,使用授权 header 是惯例和标准,但不是必需的。代码示例应该清楚地表明您真正需要的是传递该令牌以使用 Firebase Admin SDK 进行验证。