GithubHelp home page GithubHelp logo

superlistapp / google_sign_in_dart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from long1eu/google_sign_in_dart

5.0 1.0 1.0 280 KB

License: Other

Kotlin 0.14% TypeScript 2.45% Ruby 4.46% Swift 1.37% Objective-C 0.04% Dart 52.09% CMake 15.35% C++ 20.72% C 1.39% HTML 2.00%

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

google_sign_in_dart's People

Contributors

brian-superlist avatar jvelezos avatar long1eu avatar pr-mais avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tgrangeray

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.