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
- depend on it
dependencies: google_sign_in: ^4.1.4 google_sign_in_dartio: ^0.0.6
- run
flutter pub get
- import
import 'package:google_sign_in/google_sign_in.dart'; import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';
- 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 theregister
method to finish before calling anygooglesignin
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
- go to the google cloud platform console and select you project
- go to
apis & service
->credentials
- create new credentials for your app by selecting
create credentials
and thenoauth client id
- select
other
asapplication type
, give it a name (eg. macos) and then clickcreate
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.
Comments are closed.