javascript - How to safely use Firebase Auth on a PHP web app - Stack Overflow

I am building a news website on with PHP and MySQL. For user management, I'm considering using Fir

I am building a news website on with PHP and MySQL. For user management, I'm considering using Firebase Auth.

The login, password, email confirmation, etc, will be managed by Firebase. This part was easily achieved using the docs in Javascript.

But at one point the web app needs to know the email of user, for example, to manage the content and allow access to restricted areas, connecting to the MySQL DB using PHP.

Firebase Auth uses JavaScript to find out the email for example:

      firebase.auth().onAuthStateChanged(function(user) {

                var user = firebase.auth().currentUser;

                if(user != null){

                  var email_id = user.email;

                }
        }

How can I safely get the user email logged in on the session and send to the server side using PHP? How can I safely be sure the session expired and let the app know about that using PHP? Is this approach remended (Firebase Auth + PHP website)?

Thanks!

I am building a news website on with PHP and MySQL. For user management, I'm considering using Firebase Auth.

The login, password, email confirmation, etc, will be managed by Firebase. This part was easily achieved using the docs in Javascript.

But at one point the web app needs to know the email of user, for example, to manage the content and allow access to restricted areas, connecting to the MySQL DB using PHP.

Firebase Auth uses JavaScript to find out the email for example:

      firebase.auth().onAuthStateChanged(function(user) {

                var user = firebase.auth().currentUser;

                if(user != null){

                  var email_id = user.email;

                }
        }

How can I safely get the user email logged in on the session and send to the server side using PHP? How can I safely be sure the session expired and let the app know about that using PHP? Is this approach remended (Firebase Auth + PHP website)?

Thanks!

Share Improve this question asked Aug 15, 2018 at 19:52 tomDevtomDev 5,7605 gold badges33 silver badges41 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

To securely know what user is accessing your web site, you:

  1. retrieve the ID token of the user on the client
  2. securely send the resulting JWT to your back-end
  3. decode and verify the ID token on your back-end

Ideally you'd use the Firebase Admin SDK for that last step. But unfortunately there is no official Firebase Admin SDK for PHP (yet). There is a third party library that seems to support validating ID tokens in PHP, but I never tried that myself. Of course, JWT is a well-defined standard, so there are support libraries for many languages on https://jwt.io/.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743736908a4498424.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信