gpt4 book ai didi

android - Firebase 身份验证 : Getting an AuthCredential after sign in using FirebaseUI-Android

转载 作者:行者123 更新时间:2023-12-05 07:45:42 25 4
gpt4 key购买 nike

我有一个 Android 应用程序,其中包含一些 Activity 和一个长期运行的服务。该服务有一些模型类,存储在 Firebase 数据库中的 POJO。

在首次运行时,该应用确定用户尚未登录,并使用 FirebaseUI-Android 提供带有 Google 和 Facebook 的帐户选择器 Activity 。这很常见:

    Intent signInIntent = AuthUI.getInstance().createSignInIntentBuilder()
.setProviders(Arrays.asList(
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build()))
.setTheme(R.style.AppThemeFirebaseAuth)
.setLogo(R.drawable.logo)
.setIsSmartLockEnabled(!BuildConfig.DEBUG)
.build();

activity.startActivityForResult(signInIntent, Request.FIREBASE_AUTH);

然后我可以获得一个 FirebaseUser 并开始使用数据库进行操作。

FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

DatabaseReference firebaseUserRef = FirebaseDatabase.getInstance().getReference("users").child(firebaseUser.getUid());

问题出现在服务的下一次运行时,这可能是在没有 Activity 的时候。我想再次进行一些数据库操作,但没有任何用户交互。看起来我需要调用 FirebaseAuth.signInWithCredential(),但我从哪里获得 AuthCredential 引用? AuthCredential 不会传回开始登录的 Activity 。

我可以使用 FirebaseUI-Android 中的 Smart Lock 东西来帮忙吗?

最佳答案

你不能。从这个线程 https://github.com/firebase/FirebaseUI-Android/issues/123

Ah, we have a slight problem here after discussing this with some colleagues. There is deliberately no way to get back an AuthCredential from an existing user, to avoid potentially leaking credentials. So, the linking of the authentication method to the anonymous account would have to occur within Firebase UI if you are using the library. I'll take a look at this next week to get you unblocked ASAP

关于android - Firebase 身份验证 : Getting an AuthCredential after sign in using FirebaseUI-Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41434288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com