GAE3 Python和验证Firebase令牌服务器端(我们是否需要每次都调用Firebase?)

时间:2020-08-18 05:44:56

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

这是我的第一个GAE应用,因此,如果我的方法有误,请告诉我。我了解Flask,并在满足身份验证需求之前使用过Flask-Login。对于GAE,他们似乎建议使用Firebase。我的不是SPA,但我想使用Firebase UI并让它处理所有用户身份验证部分。

看这里的示例https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard_python3/building-an-app/building-an-app-3/static/script.js#L42,我可以使用Python Admin SDK验证令牌服务器端。 https://firebase.google.com/docs/auth/admin/verify-id-tokens#python或更完善的示例https://firebase.google.com/docs/auth/admin/manage-cookies#python。我能够做到这一点,但稍后对流程有点困惑。

在同一示例中,他们建议将令牌(或声明的某些部分)存储为安全cookie。这类似于Flask Login也存储cookie的方式,然后我们在每个请求中验证cookie,但是由于后端是本地REDIS或任何存储,因此验证并不昂贵。但是在使用Firebase时,似乎我们必须为每个api调用都调用Firebase来验证令牌。

否则,可能是用户更改了密码或在其Google / Facebook提供程序中重置了某些内容,直到我们在提供程序端进行验证之前,我们不会在服务器上知道。这也阻止我们离线进行本地开发(或者我们编写一些逻辑来专门处理本地开发)。

解决此问题的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以使用Firebase Admin SDK来管理用户或管理身份验证令牌,according to the official documentation – marian.vladoi

相关问题