Firebase如何通过本机Facebook应用验证用户

Jar*_*nal 8 cordova firebase firebase-security

firebase身份验证API使用浏览器弹出窗口(新api cordova示例中的Firebase.authWithOAuthPopup()).但是,在手机上,大多数人使用原生的Facebook应用程序.对于Cordova手机应用程序,通过fb本机应用程序进行身份验证的优点是不要求用户重新输入Facebook用户名和密码.

如何使用firebase api实现fb本机应用程序身份验证?

如果firebase本身不支持fb本机应用程序身份验证,是否可以将firebase与cordova facebook插件结合使用,这似乎支持本机fb app auth.怎么可以这样做?

Chr*_*nor 22

authWithOAuthPopup()方法不支持本机身份验证流,但是,使用Firebase引用的authWithOAuthToken()方法,您可以使用Cordova Facebook插件返回的OAuth令牌登录Firebase.

这是一个例子:

var dataRef = new Firebase('https://<your-firebase>.firebaseio.com');

facebookConnectPlugin.login(['public_info'], function(status) {
  facebookConnectPlugin.getAccessToken(function(token) {
    // Authenticate with Facebook using an existing OAuth 2.0 access token
    dataRef.authWithOAuthToken("facebook", token, function(error, authData) {
      if (error) {
        console.log('Firebase login failed!', error);
      } else {
        console.log('Authenticated successfully with payload:', authData);
      }
    });
  }, function(error) {
    console.log('Could not get access token', error);
  });
}, function(error) {
  console.log('An error occurred logging the user in', error);
});
Run Code Online (Sandbox Code Playgroud)