我正在尝试使用Firebase Auth服务和电子邮件和密码.当我点击注册时,我在模拟器上收到一条警告说:
"Update Google Play services : Firebase Auth won't run unless you update Google Play services"
Run Code Online (Sandbox Code Playgroud)
当我查看日志时,我可以阅读这两行:
DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
GooglePlayServicesUtil: Google Play services out of date. Requires 9256000 but found 9080480
Run Code Online (Sandbox Code Playgroud)
在SDK Manager中,Google Play服务是最新的.我怀疑它是模拟器的一个问题,它不知何故是最新的.
我正在使用的模拟器:Nexus 5X API 21(使用Google API)
任何的想法?谢谢!
android firebase google-play-services firebase-authentication
我正在使用谷歌的firebase,我在用户身份验证方面遇到了一些麻烦.使用Facebook登录后,我在AuthStateListener中获取FirebaseUser,但是如何通过facebook或不同方式检测此用户是否已记录?
更新正如@Frank van Puffelen所说,FirebaseAuth.getInstance().getCurrentUser().getProviderId()应该返回"facebook",但在我的情况下它会返回"firebase".现在我无法弄清楚这种行为的原因是什么.当我收到FacebookToken时,我会这样做:
AuthCredential credential = FacebookAuthProvider.getCredential(facebookToken.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
}
}
});
Run Code Online (Sandbox Code Playgroud)
然后在调用onComplete()方法之前,我的AuthStateListener获取用户哪个提供者ID不应该是"facebook".难道我做错了什么?我按照官方谷歌文档
reauthenticate()在Firebase中使用的示例仅显示如何重新验证使用电子邮件和密码签名的用户:
AuthCredential credential = EmailAuthProvider.getCredential("user@example.com", "password1234");
FirebaseAuth.getInstance().getCurrentUser().reauthenticate(credential);
Run Code Online (Sandbox Code Playgroud)
我也知道如何使用Facebook Provider(credential = FacebookAuthProvider.getCredential(AccessToken.getCurrentAccessToken().toString()))重新进行身份验证.
问题是Google API中没有等效方法来获取当前的访问令牌并最终获得AuthCredential.那么getCredential()在这种情况下我会传递什么?
我在两个android项目中遇到这个问题.在一个我试图从Firebase检索数据到Recyclerview和另一个我试图使用电话号码登录但在两种情况下logcat显示V/FA:
Inactivity, disconnecting from the service
Run Code Online (Sandbox Code Playgroud) 在我的服务器上,我在使用firebase admin sdk时看到了这些错误 .verifyIdToken()
Firebase ID令牌已过期.从您的客户端应用中获取新的令牌,然后重试
Firebase ID令牌具有"kid"声明,该声明与已知的公钥不对应.很可能ID令牌已过期,因此请从您的客户端应用获取新令牌,然后重试.有关如何检索ID令牌的详细信息,请参阅https://firebase.google.com/docs/auth/admin/verify-id-tokens.
在客户端,我在浏览器<>服务器之间的每个请求之前执行此操作:
firebase.auth().currentUser.getIdToken()
Run Code Online (Sandbox Code Playgroud)
通过阅读文档,我的理解是此函数将获得有效的,未过期的令牌,因为后台的SDK将根据需要自行刷新.或者,我可以传入true此功能以强制刷新.
为什么这个getIdToken()函数似乎是将过期的令牌发送到我的后端?
似乎要解决这个问题我的选择是:
true强制刷新每次我打电话getIdToken时间().这是不必要的昂贵,因为它会在来自浏览器<>我的服务器的请求之前从浏览器<> firebase添加整个往返网络请求的开销getIdToken()我现在的方式 - 在客户端手动解码令牌,检查到期,如果它已过期然后getIdToken(true)再次调用强制刷新并将新刷新的令牌发送到我的服务器2号是推荐/预期的处理方式吗?看来这里有些不对劲......
我在App Store中有一个Android应用。它在后端使用Firebase,并通过Facebook(和Google)提供社交登录。
最近,Facebook联系我,警告我通过Facebook登录时我的应用程序崩溃/无响应。感到困惑,我开始进行一些测试。
我发现,如果我在未安装Facebook应用程序的情况下使用Facebook登录名,则一切运行正常。向用户显示一个浏览器窗口,可以登录,他们被重定向回我的应用程序,并且我具有他们的身份。当然,我在开发过程中发现了所有这些内容,但只是想确认一切仍然正常。
但是,当我安装Facebook应用程序时(在开发过程中我忽略了这一点),我发现它不再起作用。而是,用户被重定向到此页面:
为了便于搜索和访问,该图像中的文字为:
登录错误:将您登录到此应用程序时出错。请稍后再试。
发生这种情况时,我已经检查了日志,发现以下内容可能相关,但我不确定:
07-05 15:36:28.468 908 5828 I ActivityManager: START u0 {act=NATIVE_WITH_FALLBACK cmp=<<redacted>>/com.facebook.FacebookActivity (has extras)} from uid 10264
07-05 15:36:28.469 665 665 D QCOM PowerHAL: LAUNCH HINT: ON
07-05 15:36:28.470 665 665 D QCOM PowerHAL: Activity launch hint handled
07-05 15:36:28.495 4837 4837 W ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@e64bd3e
07-05 15:36:28.689 665 665 D QCOM PowerHAL: LAUNCH HINT: OFF
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: Exception during service
07-05 15:36:28.946 29406 …Run Code Online (Sandbox Code Playgroud) android facebook facebook-authentication firebase firebase-authentication
我正在使用 iPhone 12 Pro Max 模拟器、macOS Catalina。
\n当我尝试运行该应用程序时,出现此错误:
\n[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.\nRun Code Online (Sandbox Code Playgroud)\n控制台中还有一个提示: \n通常这意味着您在调用 之前已尝试使用 Firebase 服务Firebase.initializeApp。
我在使用 Firebase 之前对其进行初始化。像这样:
\nvoid main() async {\n print(\'-- main\');\n\n WidgetsFlutterBinding.ensureInitialized();\n print(\'-- WidgetsFlutterBinding.ensureInitialized\');\n\n await Firebase.initializeApp();\n print(\'-- main: Firebase.initializeApp\');\n\n runApp(const MyApp());\n}\nRun Code Online (Sandbox Code Playgroud)\n这是我在控制台输出中看到的内容:
\nXcode build done. 132.9s\nflutter: -- main\nflutter: -- WidgetsFlutterBinding.ensureInitialized\n[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.\n\nUsually this means you\'ve attempted to use a Firebase service before calling …Run Code Online (Sandbox Code Playgroud) 我已成功部署了https://firebase.google.com/docs/auth/android/facebook-login中的教程代码,以便将Firebase身份验证登录与Facebook集成.用户已在Firebase Auth控制台中成功创建.
但是,我注意到用户对象中的电子邮件字段为空( - ).奇怪的是,我使用获取的令牌使用GraphRequest直接从提供者结果对象中成功检索了电子邮件信息.
根据我阅读的文档(https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser.html#getEmail()),应从登录提供商填充电子邮件字段.
一些额外的奇怪行为:
有什么我想念或做的我做错了吗?
这是我的代码:
public class LoginActivity extends AppCompatActivity {
private static final String TAG = "LOGIN_ACTIVITY";
private static final int RC_SIGN_IN = 777;
private EventBus eventBus;
private SweetAlertDialog pDialog;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private CallbackManager mCallbackManager;
private ImageView mPasswordVisibilityView;
private TextView txtPassword;
private boolean justEnteredAuthStateChanged = false;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.login);
// Firebase
mAuth = FirebaseAuth.getInstance();
mAuthListener …Run Code Online (Sandbox Code Playgroud) android facebook-authentication firebase firebase-authentication
我正在尝试使用Firebase Auth为Angular 2路由构建AuthGuard.
这是AuthGuard服务:
import { Injectable } from '@angular/core';
import { CanActivate, Router,
ActivatedRouteSnapshot,
RouterStateSnapshot } from '@angular/router';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private AuthService: AuthService,
private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.AuthService.loggedIn) { return true; }
this.router.navigate(['login']);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这是AuthService,它检查用户是否登录并将结果绑定到其构造函数中的"loggedIn"属性.
import { Injectable } from '@angular/core';
import { AngularFire } from 'angularfire2';
import { Router } from '@angular/router';
@Injectable()
export class AuthService {
loggedIn: …Run Code Online (Sandbox Code Playgroud) firebase typescript firebase-authentication angularfire2 angular
我有一个调用addCheckin()方法的页面,它位于控制器内部.在控制器中,我试图创建一个如下引用:
var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");
Run Code Online (Sandbox Code Playgroud)
$scope.whichuser并且$scope.whichmeeting是$routeParams,我从其他途径传递.这是我的签到控制器 -
myApp.controller("CheckinsController",
['$scope','$rootScope','$firebaseArray','$routeParams','$firebaseObject',
function($scope,$rootScope,$firebaseArray,$routeParams,$firebaseObject){
$scope.whichuser = $routeParams.uid;
$scope.whichmeeting = $routeParams.mid;
var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");
$scope.addCheckin = function(){
var checkinInfo = $firebaseArray(ref);
var data={
firstname:$scope.firstname,
lastname:$scope.lastname,
email:$scope.email,
date:firebase.database.ServerValue.TIMESTAMP
}
checkinInfo.$add(data);
}
}]);/*controller*/
Run Code Online (Sandbox Code Playgroud)
我在这里遇到两个错误 -
错误1:
Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings: Client doesn't have permission to access the desired data.
错误2:
Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings/-KT5tqMYKXsFssmcRLm6/checkins: Client …
angularjs firebase angularfire firebase-authentication firebase-realtime-database
firebase ×10
android ×6
angular ×1
angularfire ×1
angularfire2 ×1
angularjs ×1
facebook ×1
flutter ×1
flutter-ios ×1
logcat ×1
typescript ×1