Flutter Windows Google Authentication Without google_sign_in



google_sign_in包似乎不支持Windows上的Google身份验证。有没有一种方法做谷歌登录在Flutter Windows没有这个包?我猜我们需要打开一个web视图,将用户带到谷歌登录,然后在用户登录后以某种方式检索令牌。一个样本会非常棒。

您可以使用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。我很快会亲自测试的。

最新更新