簡體   English   中英

Flutter Web Google 登錄

[英]Flutter Web Google Sign In

我嘗試在 Flutter Web 中使用 Google 實現登錄。 我使用GoogleSignn 4.1.1Firebase Auth 0.15.4 我沒有收到任何錯誤消息。 它只是不彈出。

  • 我在 Firebase 中注冊了 Web 應用程序(添加的依賴項),甚至添加了帶有google-signin-client_id<meta>標簽
  • 當我在 Android 上運行 Firebase Auth with Google 時它可以工作
  • 我還在 Web 中從 GoogleSignIn 運行了示例應用程序 它也不會彈出。

這是我的登錄代碼(適用於 Android)

    final FirebaseAuth _auth = FirebaseAuth.instance;
    FirebaseUser user = await _auth.currentUser();
    if (user != null) {
      log.d('alreadyLoggedIn');
    } else {
      final GoogleSignIn _googleSignIn = GoogleSignIn(clientId: Constants.GOOGLE_SIGN_IN_CLIENT_ID);
      final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
      final GoogleSignInAuthentication googleAuth =
          await googleUser.authentication;
      final AuthCredential credential = GoogleAuthProvider.getCredential(
        accessToken: googleAuth.accessToken,
        idToken: googleAuth.idToken,
      );
      await _auth.signInWithCredential(credential);
      user = await _auth.currentUser();
      assert(user.email != null);
      assert(user.displayName != null);
      assert(!user.isAnonymous);
      assert(await user.getIdToken() != null);
    }
    return user;
    }

我希望有人知道如何解決這個問題。

您是否遵循了此頁面中的所有說明(包括將 OAuth ID 添加到 index.html)? https://pub.dev/packages/google_sign_in_web

您從https://console.developers.google.com/apis/credentials獲取您的客戶 ID

您還必須像這樣從終端運行,以便在調試時在本地主機上運行:

flutter run -d chrome --web-hostname localhost --web-port 5000

默認授權端口為 5000,您可以在獲得 CLIENT ID 的同一頁面上添加其他 URI(例如8764367243864-987523.apps.googleusercontent.com),它位於“Authorised JavaScript origins” https://console.developers.google 下。 com/apis/憑證

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM