How to validate an authentication token against firebase?

断了今生、忘了曾经 提交于 2019-12-22 08:24:11

问题


I don't mean custom authentication with firebase. What I need is slightly different from that custom authentication that generates tokens in application server and allows access in firebase. Actually, I'm trying to authenticate in firebase with e-mail and password , for instance, and with that authentication be able to access restful services in some application server. Is this possible ? I think that in some way an token could be sent to application server after firebase authentication and that server would validate the auth token against firebase.

Client --------authenticates ------->> Firebase
Client <<--------auth token ---------- Firebase
Client --------- sends ------------->> Application server (NodeJS)
App Server ------- validates (auth token) ---->> Firebase

Thanks in advance.


回答1:


You can get the token with the async getToken method available in iOS, Web and Android

Web:

https://firebase.google.com/docs/reference/js/firebase.User#getToken

iOS: https://firebase.google.com/docs/reference/ios/firebaseauth/interface_f_i_r_user#properties

Android: https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser.html#public-constructor-summary

And send that token to your backend server, then you can use the verifyIdToken method in the server to validate the token and get the token's uid

Server method https://firebase.google.com/docs/auth/server#verify_id_tokens



来源:https://stackoverflow.com/questions/37548567/how-to-validate-an-authentication-token-against-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!