Firebase身份验证无法在我的Flutter应用中使用Google登录

时间:2019-04-17 17:32:57

标签: dart flutter firebase-authentication google-signin

我在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));
              });
            },

在这里,您拥有我的auth服务的某些部分:

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;
  }
}

您看到错误在哪里吗? 提前致谢。 杰里米。

0 个答案:

没有答案