Flutter - 谷歌登录能否在没有Firebase的情况下使用?

18

请参考以下链接:https://medium.com/flutter-community/flutter-sign-in-with-google-in-android-without-firebase-a91b977d166f。 - Ashok Kumar N
3个回答

19

可以!

  1. 在云控制台中创建项目。

  2. 创建OAuth 2.0客户端ID(通过包名限制)

  3. 下载JSON文件并将其放置在android->app文件夹中,就这样。

  4. 按照google_sign_in包中的步骤进行操作,而不涉及Firebase。

 GoogleSignIn googleSignIn = GoogleSignIn(
   clientId:"xxxx.apps.googleusercontent.com");

clientId是可选的,但在Flutter Web中是必需的。

另请参考Flutter Web使用Google账号登录而无需Firebase


6
谷歌登录在苹果设备上怎么样? - Sajad Abdollahi
1
这在iOS上运行良好吗? - Quwaysim

4

是的,试试使用 visa - https://github.com/e-oj/visa

以下是一个使用 Facebook 认证的示例(也支持 Google、Twitch、Discord 和 Github):

import 'package:visa/auth-data.dart';
import 'package:visa/fb.dart';

class AuthPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      /// Simply Provide all the necessary credentials
      body: FaceBookAuth().visa.authenticate(
          clientID: '139732240983759',
          redirectUri: 'https://www.e-oj.com/oauth',
          scope: 'public_profile,email',
          state: 'fbAuth',
          onDone: done
      )
    );
  }
}

和 "done" 回调函数:

done(AuthData authData){
  print(authData);

  /// You can pass the [AuthData] object to a 
  /// post-authentication screen. It contaions 
  /// all the user and OAuth data collected during
  /// the authentication process. In this example,
  /// our post-authentication screen is "complete-profile".
  Navigator.pushReplacementNamed(
      context, '/complete-profile', arguments: authData
  );
}

0
如果您已完成上述OAuth 2.0客户端ID步骤,则在发布到Google Play等平台后,您的Google登录按钮可能无法正常工作。为此,请进入您的Google Cloud帐户,并从OAuth客户端ID部分创建另一个包名称和签名密钥区域。然后将Google Play提供给您的签名密钥(SHA-1)粘贴到那里。它将在几个小时内开始工作。 输入图像描述

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接