Can I access twitter auth data via firebase cloud functions Admin SDK? If so, how?

Viewed 35

I'm currently using firebase for the backend of a project I'm working on. In this project, the client authenticates using the firebase-twitter sign in method. For the purpose of security, I'm trying to minimise the amount of communication between the client and backend when it comes to auth data. In jest of this, I'm wondering if there is a way to access the auth data i.e. the user's twitter key/secret (as well as things like the user's twitter handle) from the server-side after the user authenticates ? I figured there might be a way as the authentication happens through twitter + firebase, but I'm struggling to find the exact solution I need in the documentation (been stuck on this for a week now) so was hoping someone else already knows if this is possible and how :) cheers

1 Answers

Maybe not the best way, but you can try: on client side use RealTime database and add a new entry every time the user log in. They call this 'realtime triggers'.

You don't mention what front are you using, but on ionic is something like:

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

  if (user)
      this.db.addLogin(user.uid)               
 });  

On database class function:

 addLogin(uid){
  let path = "/logins/" 
  let ref = this.db.list(path)

  let body = {uid: uid}
  return ref.push(body)
 }      

On the server side, listen the path using child_added

var ref = db.ref("logins");

ref.on("child_added", function(snapshot, prevChildKey) {
  var newPost = snapshot.val();
  console.log("Uid: " + newPost.uid);
  console.log("Previous Post ID: " + prevChildKey);
});

More information about triggers

Related