google_sign_in_dartio
用于 Google 登录的 Flutter 包,使用 Dart 编写,并支持移动和桌面环境。
long1eu/google_sign_in_dart open-source repository details.
{"sdk":"flutter"}^6.2.0^2.4.3^2.2.2^2.3.4^2.3.2^6.2.1^3.1.0^3.0.3^1.1.2^2.0.0{"sdk":"flutter"}以下为英文项目原文快照,最新内容请访问 GitHub。
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.
dependencies:
google_sign_in: ^4.1.4
google_sign_in_dartio: ^0.0.6
flutter pub getimport 'package:google_sign_in/google_sign_in.dart';
import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';
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.You can use the normal GoogleSignIn methods.
final GoogleSignInAccount account = await GoogleSignIn().signIn();
APIs & Service -> CredentialsCREATE CREDENTIALS and then OAuth client IDOther as Application type, give it a name (eg. macOS) and then click CreateThe 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.
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());
}
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.