搜索插件、代码仓与 APP 分类

插件详情v0.3.0

google_sign_in_dartio

用于 Google 登录的 Flutter 包,使用 Dart 编写,并支持移动和桌面环境。

AndroidiOSmacOS
近 30 天下载
9710
喜欢数
29
Pub 分数
150

安装插件

flutter pub add google_sign_in_dartio

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,使用纯 Dart 实现 Google 登录,支持 Android、iOS 和 macOS。它提供了一种跨平台的认证解决方案,无需依赖原生代码,简化了在移动和桌面环境中的集成。该包专为希望在 Flutter 应用中采用轻量级、统一方法进行 Google 认证的开发者设计。

适合场景

  • 跨平台应用中的用户身份验证
  • 简化移动和桌面端的登录流程
  • 在Flutter应用程序中集成Google账户
  • 启用无需原生依赖的安全登录
  • 支持多平台身份管理

主要特点

  • 纯 Dart 实现
  • 跨平台支持(Android、iOS、macOS)
  • 无需原生代码
  • 轻量且易于集成
  • 内置的 OAuth2 令牌处理

适合对象

  • 针对多个平台的开发人员,使用共享的身份验证逻辑
  • 项目避免使用平台特定的原生代码
  • 桌面和移动设备上需要无缝 Google 登录的应用程序
  • 优先考虑跨平台代码一致性的团队
  • 需要最少设置即可进行 Google 身份验证的应用程序

使用建议

  • 仅限 Google 登录
  • 需要在 Google Cloud 控制台中进行正确配置
  • 与平台特定的 SDK 相比,功能可能更少
  • 依赖互联网连接进行身份验证
  • 不适合用于复杂的OAuth工作流,仅适用于基本登录

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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.

所属分类

依赖

依赖清单 10 项

源码仓库

使用此插件的项目

暂无相关数据。