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 recommended (Firebase Auth + PHP website)?
Thanks!
Q: Can I use Firebase with PHP? A: Yes, Firebase provides a comprehensive API for integrating the platform with your PHP projects.
As a default Firebase database has no security, it's the development team's responsibility to correctly secure the database prior to it storing real data. In Google Firebase, this is done by requiring authentication and implementing rule-based authorization for each database table.
Firebase gives you complete control over authentication by allowing you to authenticate users or devices using secure JSON Web Tokens (JWTs). You generate these tokens on your server, pass them back to a client device, and then use them to authenticate via the signInWithCustomToken() method.
To securely know what user is accessing your web site, you:
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/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With