Git Product home page Git Product logo

google_sign_in_dart's Introduction

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) {
        GoogleSignInDart.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) {
        GoogleSignInDart.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.

google_sign_in_dart's People

Contributors

long1eu avatar nilsreichardt avatar amichai-a avatar timyusr avatar pr-mais avatar

Stargazers

Joe avatar  avatar Kosei Akaboshi avatar mono โ€” Masayuki Ono avatar  avatar Ihor Kozar avatar  avatar Paul Mutisya avatar Tushar Asodariya avatar Joohun, Maeng avatar Roman avatar Alexander Mateo avatar Adrian Kalbarczyk avatar Reuben Turner avatar

Watchers

James Cloos avatar  avatar

google_sign_in_dart's Issues

Loopback is no longer supported for certain platforms

Certain OAuths meant for platforms such as android will no longer work with this library as Loopback has been disabled. As such, opening the login page will now block access with Error 400: invalid_request. For more information see here.

[docs] Add documentation to set up redirect URIs

In most cases, people will attempt follow what's added on the front page of the package. It would be great to provide some context at the bare minimum how to setup redirect URIs for OAuth2.

For example, someone will get redirected to this screen in the default browser:
Screenshot 2023-02-09 at 1 32 32 AM

Outlining this on the README page would help save time for other developers:
Screenshot 2023-02-09 at 1 32 43 AM

The package should assume they're using this package mainly for macOS and not haven't integrated iOS yet. So some prerequisite setup might not have been made for the latter.

Version solving failed, please update http package and enable null safety.

[yourapp] flutter pub add google_sign_in_dartio
The current Dart SDK version is 3.3.0-142.0.dev.

Because google_sign_in_dartio >=0.1.0 <0.2.2+1 depends on http ^0.13.3 and google_sign_in_dartio <0.1.0 doesn't support null safety, google_sign_in_dartio <0.2.2+1 requires http ^0.13.3.
And because google_sign_in_dartio >=0.2.2+1 depends on http ^0.13.5, every version of google_sign_in_dartio requires http ^0.13.3.
So, because yourapp depends on both http ^1.1.0 and google_sign_in_dartio any, version solving failed.

The lower bound of "sdk: '>=2.1.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.
For details, see https://dart.dev/null-safety
exit code 65

Redirect uri?

Is there a place to set the redirect uri? It's actually popping up on my desktop, but using FirebaseAuth, it is returning a 'Error 400: redirect_uri_mismatch' error that the request uri is not present. Of course the request uri changes on desktop version it appears: 127.0.0.1:xxx the port constantly changes, so it cant be set in the Oauth panel of google.

flutter: PlatformException(failed_to_recover_auth,

<title>503 Service Unavailable</title>

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

, null, null)

is that package working with windows?

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
  );
  await GoogleSignInDart.register(
    exchangeEndpoint:
        'https://europe-west-flutter-sdk.cloudfunctions.net/authHandler',
    clientId:
       <CLIENTID>,
  );
  runApp(MyApp());
}
GoogleSignIn _googleSignIn = GoogleSignIn(scopes: <String>[
  'email',
  'profile',
]);
 ------------------------------------------------------------------------------------------------
ElevatedButton(
                    onPressed: () async {
                      await _googleSignIn.signIn();
                    },
                    child: Text("GOOGLE"))

when i click that 'GOOGLE' button i get platform error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method launch on channel plugins.flutter.io/url_launcher_windows)

Custom DataStorage not possible

First of all, thank you so much for this project.
It is very helpful for using Google Sign In on Windows.

I am trying to override the default SharedPreferences DataStorage.
I understand I need to implement my own Store, akin the _SharedPreferencesStore.

However, I am not able to pass that implementation to the plugin because the DataStorage has only a private constructor.
I could implement DataStorage from scratch, however I am wondering if I am missing something obvious. Shouldn't it have a public constructor as well to pass custom Store implementations?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.