我想使用Firebase构建Android应用。 Firebase为登录屏幕https://github.com/firebase/firebase-login-demo-android提供演示代码。
但我不想让用户输入他们的帐户信息,我希望用户能够使用用户已经在Android的集中帐户管理中输入的帐户信息。< / p>
我已经在https://developer.android.com/reference/android/accounts/AccountManager.html看到了AccountManager
对象的文档,在https://www.firebase.com/docs/android/guide/user-auth.html看到了Firebase Android身份验证指南,但是我对于菜鸟来说太过分了如何将它们放在一起。
任何建议/指针/示例代码将不胜感激。或者让我知道我是否在咆哮错误的树。
答案 0 :(得分:1)
Firebase工程师,
这是一种完全合法的方式 - 过去我们有很多人选择整合这种方式。
简短的回答是,它需要两个步骤:
看起来像this is a good resource for the first step(了解AccountManager)。然后在doCoolAuthenticatedStuff()中,您将关注我们的typical auth flow:
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世界中有一个example of something similar(使用ACAccountStore进行Twitter登录,这与Android AccountManager非常相似),如果流程有帮助的话。
这听起来好像会成为一个好的食谱/要点,所以我会看到我能做什么!