The google_sign_in package doesn't seem to support Google authentication on Windows. Is there a way to do Google sign-in on Flutter Windows without this package? I'm guessing that we need to open a web view that takes the user to Google sign-in and then somehow retrieves the token after the user has signed in. A sample would be really awesome.
Asked
Active
Viewed 1,724 times
1
-
This answer gets you what you want (although still using google-sign-in): https://stackoverflow.com/questions/68716993/google-microsoft-oauth2-login-flow-flutter-desktop-macos-windows-linux – Oded Ben Dov Jul 06 '22 at 07:03
2 Answers
1
You can use 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();
});
}
daijikaijuu
- 145
- 1
- 6
-
1This looks promising. Where are the Client and DriveApi classes from? Which package? Is there a working sample I can look at somewhere? This does not compile for me even with the googleapis_auth installed – Christian Findlay Sep 04 '21 at 04:03
0
There is a note in this plugin - to not be used in flutter app, as it could be decompiled and the secret exposed. Others have had similar requirements and have done a workaround https://bselwesiuk.medium.com/social-authentication-in-flutter-desktop-apps-c8c0599e13d3 . Will test it myself soon.
Toma Velev
- 81
- 1
- 3