使用与facebook图形API的firebase脸书认证 [英] Using firebase facebook auth with facebook graph api

查看:141
本文介绍了使用与facebook图形API的firebase脸书认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用firebase facebook简单登录。

有没有什么办法可以把它和facebook的js图形API结合使用?

假设调用 FB.api('xxx',function(){})

解决方案

Facebook通过Firebase Simple登录将Facebook访问令牌作为有效负载的一部分返回。然后,您可以直接使用Facebook Graph API及其 JavaScript SDK : p>

  var ref = new Firebase(URL); 
var auth = new FirebaseSimpleLogin(ref,function(error,user){
if(user){
var facebookToken = user.accessToken; //<< - 这里是
}
});

//注意:将其添加到点击事件中,以允许弹出窗口显示
auth.login('facebook');

正如您所指出的,Singly是另一种抽象化与Facebook交谈的一个很好的方法,如果你的用例是相当简单的,那就不需要这样做。

UPDATE

> Firebase Simple Login现在支持使用现有的Facebook访问令牌对用户进行身份验证,这意味着您可以轻松地将Facebook JS SDK与Firebase Simple Login结合使用,而无需要求用户进行两次验证。



例如,一旦您使用Facebook JS SDK获得有效的Facebook访问令牌:

  var ref = new火力地堡(...); 
var auth = new FirebaseSimpleLogin(ref,function(error,user){...});
auth.login('facebook',{access_token:'< ACCESS_TOKEN>'});

access_token =https://www.firebase.com/docs/security/simple-login-facebook.html =nofollow> https://www.firebase.com/docs/security/simple-login-facebook。 html 获取更多信息。


I am using firebase facebook simple login.

Is there any way I can use it conjunction with facebook js graph api?

Let say, calling FB.api('xxx', function(){}) ?

解决方案

Facebook via Firebase Simple Login returns the Facebook access token as part of the payload. You could then use this directly with the Facebook Graph API and their JavaScript SDK:

var ref = new Firebase(URL);
var auth = new FirebaseSimpleLogin(ref, function(error, user) {
  if (user) {
    var facebookToken = user.accessToken; // <<-- here it is
  }
});

// Note: Attach this to a click event to permit the pop-up to be shown
auth.login('facebook');

As you noted, Singly is another great approach that abstracts some of the effort of talking to Facebook, but shouldn't be necessary if your use case is fairly straightforward.

UPDATE

Firebase Simple Login now supports authenticating a user with an existing Facebook access token, meaning that you can easily use the Facebook JS SDK in combination with Firebase Simple Login without asking your users to authenticate twice.

For example, once you have a valid Facebook access token using the Facebook JS SDK:

var ref = new Firebase(...);
var auth = new FirebaseSimpleLogin(ref, function(error, user) { ... });
auth.login('facebook', { access_token: '<ACCESS_TOKEN>' });

See the access_token option at https://www.firebase.com/docs/security/simple-login-facebook.html for more information.

这篇关于使用与facebook图形API的firebase脸书认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆