5

我想使用 Firebase 构建一个 Android 应用程序。Firebase 为登录屏幕提供了演示代码https://github.com/firebase/firebase-login-demo-android

但不是让用户输入他们的帐户信息,我希望用户能够使用用户已经在 Android 的集中式帐户管理器中输入的帐户信息。

我在 https://developer.android.com/reference/android/accounts/AccountManager.html 看到了对象的文档,AccountManagerhttps://www.firebase.com/docs/android/看到了 Firebase android 身份验证指南guide/user-auth.html,但我太菜鸟了,无法了解如何将它们放在一起。

任何建议/指针/示例代码将不胜感激。或者让我知道我是否找错了树。

4

1 回答 1

4

Firebase 工程师在这里,

这是一种完全合法的方式——过去我们有很多人选择整合它。

简短的回答是它需要两个步骤:

  • 从 AccountManager 获取所需提供者的适当凭证/令牌
  • 使用该凭据/令牌对 Firebase 身份验证进行身份验证。

看起来这是第一步的好资源(了解 AccountManager)。然后在 doCoolAuthenticatedStuff() 中,您将遵循我们典型的身份验证流程

Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithOAuthToken("google", "<OAuth Token>", new Firebase.AuthResultHandler() {
    @Override
    public void onAuthenticated(AuthData authData) {
        // the Google user is now authenticated with your Firebase app
    }
    @Override
    public void onAuthenticationError(FirebaseError firebaseError) {
        // there was an error
    }
});

对于 Google,我们使用“电子邮件”范围,但每个提供商都会有所不同。

如果流程有帮助的话,我在 iOS 世界中有一个类似的例子(使用 ACAccountStore 登录 Twitter,这与 Android AccountManager 非常相似)。

不过,这听起来像是一个很好的食谱/要点,所以我会看看我能做什么!

于 2015-06-27T09:45:38.827 回答