GitHub 儲存庫long1eu/google_sign_in_dart

google_sign_in_dart

long1eu/google_sign_in_dart open-source repository details.

google_sign_in_dart 專案封面
星標
18
分支
20
最近推送(UTC)
2024年1月12日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

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.

Razvan Lung GitHub avatar
GitHub 作者

Razvan Lung ↗

https://www.linkedin.com/in/long1eu

România
語言DartC++CMakeRubyTypeScriptHTMLSwiftCKotlinObjective-C

此儲存庫發佈的套件

使用的依賴

依賴清單 12 項

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗