Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I integrate with firebase in a secure way without having user authentication without having server side code?

My site is just one page with a form. I don't have any user auth functionality . Can I still use client side firebase integration without passing through a server side code in a secure way? If yes how can I secure the details for my firebase connection ?

like image 262
hopper Avatar asked Oct 10 '13 10:10

hopper


2 Answers

You can use the new anonymous auth functionality provided by Firebase Simple Login: https://www.firebase.com/docs/security/simple-login-anonymous.html

With this mechanism, you can have users of your website authenticate to Firebase anonymously (they don't need to enter any login credentials), but you can still protect reads and writes to your Firebase using regular security rules.

like image 84
Anant Avatar answered Oct 15 '22 07:10

Anant


Yes.

Just add these tags to you page:

<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase.js"></script>
<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase-simple-login.js"></script>

Then write this code:

var chatRef = new Firebase('https://YOUR-APP.firebaseIO.com');
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
  if (error) {
    // an error occurred while attempting login
    console.log(error);
  } else if (user) {
    // user authenticated with Firebase
    console.log('User ID: ' + user.id + ', Provider: ' + user.provider);
  } else {
    // user is logged out
  }
});

And when your user clicks the login button, call

// attempt to log the user in with your preferred authentication provider
auth.login('github (or twitter, or what you want)');

As explained here and demonstrated here.

like image 27
fiatjaf Avatar answered Oct 15 '22 05:10

fiatjaf