Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

google_sign_in_dartio

a flutter package that implements google sign in
in pure dart. this package is compatible with google_sign_in plugin
and works on all platforms flutter supports but it’s intended to be
mainly used on desktop.

getting started

install and initialization

  1. depend on it
    dependencies:
      google_sign_in: ^4.1.4
      google_sign_in_dartio: ^0.0.6
  2. run flutter pub get
  3. import
    import 'package:google_sign_in/google_sign_in.dart';
    import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';
  4. register the package
    import 'package:flutter/material.dart';
    import 'package:google_sign_in/google_sign_in.dart';
    import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';
    
    void main() {
      if (isdesktop) {
        googlesigninplatform.register(clientid: <clientid>);
      }
    
      runapp(myapp());
    }

    note: you might want to await for the register method to finish before calling any googlesignin methods when your app starts.

usage

you can use the normal googlesignin methods.

final googlesigninaccount account = await googlesignin().signin();

obtain a client id for your desktop app

  1. go to the google cloud platform console and select you project
  2. go to apis & service -> credentials
  3. create new credentials for your app by selecting create credentials and then oauth client id
  4. select other as application type, give it a name (eg. macos) and then click create

provide a code exchange endpoint

the user accesstoken expires after about one hour, after witch you need to ask the user to login again. if you want to
keep the user logged in, you need to deploy a oauth code exchange endpoint. once you have your endpoint you can register
the package like this.

note:

if you use this only for firebaseauth you don’t need the code exchange since the token must be valid only when you
use the signinwithcredentials method.

    import 'package:flutter/material.dart';
    import 'package:google_sign_in/google_sign_in.dart';
    import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';
    
    void main() {
      if (isdesktop) {
        googlesigninplatform.register(
            clientid: <clientid>, 
            exchangeendpoint: <endpoint>,
        );
      }
    
      runapp(myapp());
    }

note:

googlesignintokendata exposes serverauthcode field that should
contain the exchange code from the authorization request. this will
always be null when using this package because we already allow you to
provide a code exchange endpoint witch exposes the code and code
verifier in a trusted environment and encourages not to do the code
exchange on the client.

see instruction on how to deploy a code exchange endpoint.


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.