使用Firebase Javascript SDK是否可以访问用户的Twitter访问令牌和密码?

时间:2019-08-02 15:20:27

标签: javascript firebase twitter firebase-authentication

我正在使用Firebase Javascript SDK,目前有用户能够注册并登录其Twitter帐户,以及通过设置链接。我想为用户提供一个选项,可以将新帖子分享到Twitter,而无需他们手动进行。

是否可以获取用户的访问令牌和机密,以便我可以向Twitter发出这样的请求?

目前,我正在使用以下代码登录:

static_framework = true

1 个答案:

答案 0 :(得分:1)

是的。它是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;
  // ...
});

示例直接取自Firebase docs