Ad

Is It Possible To Access A User's Twitter Access Token And Secret With The Firebase Javascript SDK?

I'm using the Firebase Javascript SDK and currently have users able to sign up and into, as well as link from settings, their Twitter accounts. I'd like to present users with an option to share new posts to Twitter without having them have to do it manually.

Is it possible to grab a user's access token and secret so I can make a request like this to Twitter?

Currently I'm calling sign in with this code:

doSignInWithTwitter = () =>
    this.auth.signInWithPopup(this.twitterProvider);
Ad

Answer

Yes. It is in the result of signInWithPopup:

firebase.auth().signInWithPopup(provider).then(function(result) {
  // This gives you a the Twitter OAuth 1.0 Access Token and Secret.
  // You can use these server side with your app's credentials to access the Twitter API.
  var token = result.credential.accessToken;
  var secret = result.credential.secret;
  // The signed-in user info.
  var user = result.user;
  // ...
}).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
  // ...
});

Example taken directly from Firebase docs.

Ad
source: stackoverflow.com
Ad