【问题标题】:Is it possible to access a user's Twitter access token and secret with the Firebase Javascript SDK?是否可以使用 Firebase Javascript SDK 访问用户的 Twitter 访问令牌和密钥?
【发布时间】:2019-08-02 15:20:27
【问题描述】:

我正在使用 Firebase Javascript SDK,目前有用户可以注册并进入他们的 Twitter 帐户,也可以通过设置链接。我想为用户提供一个选项,让他们无需手动操作即可将新帖子分享到 Twitter。

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

目前我正在使用此代码登录:

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

【问题讨论】:

    标签: javascript firebase twitter firebase-authentication


    【解决方案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

    【讨论】:

    • 嗨,迈克尔。是否可以检索这是用户已链接其 Twitter 帐户但使用其他表单登录的情况?比如,如果他们同时链接了自己的 Google 和 Twitter,但选择使用 Google 一次性登录?
    • 嘿,丹,如果用户将 Twitter 和 Google 链接到同一个帐户并且用户使用 Google 登录,您将只会获得 Google 凭据,因为 Firebase Auth 不存储或管理第 3 方 OAuth 凭据.它们仅返回 OAuth 流程完成后可用的内容。
    • 知道了!意识到令牌不会过期并且可以保存,它使一切变得更有意义/文档代码更好地工作。对于任何将来阅读的用户,只需存储访问令牌和密钥,用户如何验证您的应用程序并不重要。
    猜你喜欢
    • 2015-04-17
    • 2012-04-28
    • 2021-09-21
    • 1970-01-01
    • 2017-05-28
    • 2012-10-14
    • 1970-01-01
    • 2014-09-12
    • 2020-07-29
    相关资源
    最近更新 更多