Flutter Windows Google Authentication Without google_sign_in

496

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();
  });
}
Share:
496
Christian Findlay
Author by

Christian Findlay

I write about C# a lot here. I create video and written content for promotion and training. I'm about to release an Uno Platform course on Udemy. My most popular frameworks and libraries are: Device.Net, RestClient.Net, and my cryptocurrency hardwarewallet libraries on my GitHub profile. I make cross-platform apps with Uno Platform and Xamarin.Forms and work on backend in C#. Scrum.org certified Professional Scrum Product Owner

Updated on December 31, 2022

Comments

  • Christian Findlay
    Christian Findlay over 1 year

    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.

  • Christian Findlay
    Christian Findlay over 2 years
    This 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