google_sign_in 软件包似乎不支持 Windows 上的 Google 身份验证。有没有办法在没有这个包的情况下在 Flutter Windows 上进行 Google 登录?我猜我们需要打开一个 Web 视图,让用户登录 Google,然后在用户登录后以某种方式检索令牌。如果有一个示例就非常棒了。
您可以使用 googleapis_auth。
import 'package:googleapis_auth/auth_io.dart';
import 'package:url_launcher/url_launcher.dart';
void _lauchAuthInBrowser(String url) async {
await canLaunch(url) ? await launch(url) : throw 'Could not lauch $url';
}
void _loginWindowsDesktop() {
var id = ClientId(
<clientID>,
<secret>,
);
var scopes = [
'email',
'https://www.googleapis.com/auth/drive',
];
var client = Client();
obtainAccessCredentialsViaUserConsent(
id, scopes, client, (url) => _lauchAuthInBrowser(url))
.then((AccessCredentials credentials) {
final driveApi = DriveApi(client);
client.close();
});
}
此插件中有一条注释 - 不要在 flutter 应用程序中使用,因为它可能会被反编译并暴露秘密。其他人也有类似的要求,并采取了解决方法https://bselwesiuk.medium.com/social-authentication-in-flutter-desktop-apps-c8c0599e13d3。我很快就会亲自测试一下。
我找到了一个支持所有平台(包括 Windows 和 Linux)Google 登录的软件包。它称为 google_sign_in_all_platforms。我已经使用它有一段时间了,它很有魅力。