首页 > 解决方案 > Firebase 身份验证无法在我的颤振应用中使用谷歌登录

问题描述

我在我的 Flutter 应用程序中使用了 firebase-auth 和 google-signin,当点击“使用 Google 登录”按钮时,会打开一个 google 弹出窗口,以便我可以选择我想要使用的 google 帐户,当我点击在我的帐户上,弹出关闭,我在我的控制台中有这个:

D/ViewRootImpl@8929a4d[SignInHubActivity](25903): MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager(25903): Starting input: tba=android.view.inputmethod.EditorInfo@c535c6f nm : com.youpa.youpa ic=null
D/InputMethodManager(25903): startInputInner - Id : 0
I/InputMethodManager(25903): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport(25903): Input channel constructed: fd=101
D/ViewRootImpl@8929a4d[SignInHubActivity](25903): MSG_WINDOW_FOCUS_CHANGED 0
I/flutter (25903): Error : ** firebase_error.sign_in_failed not found
D/ViewRootImpl@b0e6bd3[MainActivity](25903): MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager(25903): Starting input: tba=android.view.inputmethod.EditorInfo@2825d7c nm : com.youpa.youpa ic=null
D/InputMethodManager(25903): startInputInner - Id : 0
I/InputMethodManager(25903): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport(25903): Input channel constructed: fd=110
D/InputTransport(25903): Input channel destroyed: fd=101
D/OpenGLRenderer(25903): eglDestroySurface = 0xbbbe7e60, 0xc1571800
D/ViewRootImpl@8929a4d[SignInHubActivity](25903): Relayout returned: old=[0,0][720,1280] new=[0,0][720,1280] result=0x5 surface={valid=false 0} changed=true
D/ViewRootImpl@8929a4d[SignInHubActivity](25903): dispatchDetachedFromWindow
D/InputEventReceiver(25903): channel '5a554e2 com.youpa.youpa/com.google.android.gms.auth.api.signin.internal.SignInHubActivity (client)' ~ Disposing input event receiver.
D/InputEventReceiver(25903): channel '5a554e2 com.youpa.youpa/com.google.android.gms.auth.api.signin.internal.SignInHubActivity (client)' ~NativeInputEventReceiver.
D/InputTransport(25903): Input channel destroyed: fd=97

而且我没有登录。但是,我的带有电子邮件的 firbase 身份验证系统运行良好。在这里,您有我的 Google 登录按钮的 onPressed :

onPressed: () {
              Auth()
                  .handleSignInWithGoogle()
                  .then((FirebaseUser user) {
              }).catchError((e) {
                print("Error : " +
                    internationalization
                        .text("firebase_error." + e.code));
              });
            },

在这里,您有我的身份验证服务的某些部分:

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:youpa/Model/user.model.dart';
import 'package:firebase_core/firebase_core.dart';
import 'options.services.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:io';

class Auth {
  final GoogleSignIn googleSignIn = GoogleSignIn(
    scopes: [
      'email',
      'https://www.googleapis.com/auth/contacts.readonly',
      'profile'
    ],
  );
  final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
  SharedPreferences prefs;
  final FirebaseAuth auth = FirebaseAuth.instance;

  Future<FirebaseUser> handleSignInWithGoogle() async {
    final GoogleSignInAccount googleUser = await googleSignIn.signIn();
    final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
    final AuthCredential credential = GoogleAuthProvider.getCredential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );
    FirebaseUser user = await auth.signInWithCredential(credential);
    assert(user.email != null);
    assert(user.displayName != null);
    assert(!user.isAnonymous);
    assert(await user.getIdToken() != null);

    final FirebaseUser currentUser = await auth.currentUser();
    assert(user.uid == currentUser.uid);
    print(user);
    print(currentUser);

    return user;
  }
}

你知道错误在哪里吗?提前致谢。杰里米。

标签: dartflutterfirebase-authenticationgoogle-signin

解决方案


推荐阅读