mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
Make analyzer happy.
This commit is contained in:
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: public_member_api_docs
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@ -28,11 +26,13 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The main widget of this demo.
|
||||
class SignInDemo extends StatefulWidget {
|
||||
@override
|
||||
State createState() => SignInDemoState();
|
||||
}
|
||||
|
||||
/// The state of the main widget.
|
||||
class SignInDemoState extends State<SignInDemo> {
|
||||
GoogleSignInAccount _currentUser;
|
||||
String _contactText;
|
||||
@ -56,14 +56,16 @@ class SignInDemoState extends State<SignInDemo> {
|
||||
_contactText = 'Loading contact info...';
|
||||
});
|
||||
|
||||
final peopleApi =
|
||||
final PeopleServiceApi peopleApi =
|
||||
PeopleServiceApi(await _googleSignIn.authenticatedClient());
|
||||
final response = await peopleApi.people.connections.list(
|
||||
final ListConnectionsResponse response =
|
||||
await peopleApi.people.connections.list(
|
||||
'people/me',
|
||||
personFields: 'names',
|
||||
);
|
||||
|
||||
final firstNamedContactName = _pickFirstNamedContact(response.connections);
|
||||
final String firstNamedContactName =
|
||||
_pickFirstNamedContact(response.connections);
|
||||
|
||||
setState(() {
|
||||
if (firstNamedContactName != null) {
|
||||
@ -77,12 +79,12 @@ class SignInDemoState extends State<SignInDemo> {
|
||||
String _pickFirstNamedContact(List<Person> connections) {
|
||||
return connections
|
||||
?.firstWhere(
|
||||
(person) => person.names != null,
|
||||
(Person person) => person.names != null,
|
||||
orElse: () => null,
|
||||
)
|
||||
?.names
|
||||
?.firstWhere(
|
||||
(name) => name.displayName != null,
|
||||
(Name name) => name.displayName != null,
|
||||
orElse: () => null,
|
||||
)
|
||||
?.displayName;
|
||||
|
@ -2,9 +2,6 @@ name: extension_google_sign_in_example
|
||||
description: Example of Google Sign-In plugin and googleapis.
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
google_sign_in: ^5.0.0
|
||||
extension_google_sign_in_as_googleapis_auth:
|
||||
# When depending on this package from a real application you should use:
|
||||
# extension_google_sign_in_as_googleapis_auth: ^x.y.z
|
||||
@ -12,14 +9,13 @@ dependencies:
|
||||
# The example app is bundled with the plugin so we use a path dependency on
|
||||
# the parent directory to use the current plugin's version.
|
||||
path: ../
|
||||
flutter:
|
||||
sdk: flutter
|
||||
google_sign_in: ^5.0.0
|
||||
googleapis: ^1.0.0
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: ^1.10.0
|
||||
integration_test:
|
||||
path: ../../../integration_test
|
||||
flutter_driver:
|
||||
sdk: flutter
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
@ -6,16 +6,16 @@
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:googleapis_auth/auth.dart' as googleapis_auth;
|
||||
import 'package:googleapis_auth/auth.dart' as gapis;
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
/// Extension on [GoogleSignIn] that adds an `authenticatedClient` method.
|
||||
///
|
||||
/// This method can be used to retrieve an authenticated [googleapis_auth.AuthClient]
|
||||
/// This method can be used to retrieve an authenticated [gapis.AuthClient]
|
||||
/// client that can be used with the rest of the `googleapis` libraries.
|
||||
extension GoogleApisGoogleSignInAuth on GoogleSignIn {
|
||||
/// Retrieve a `googleapis` authenticated client.
|
||||
Future<googleapis_auth.AuthClient?> authenticatedClient({
|
||||
Future<gapis.AuthClient?> authenticatedClient({
|
||||
@visibleForTesting GoogleSignInAuthentication? debugAuthentication,
|
||||
@visibleForTesting List<String>? debugScopes,
|
||||
}) async {
|
||||
@ -25,17 +25,17 @@ extension GoogleApisGoogleSignInAuth on GoogleSignIn {
|
||||
if (oathTokenString == null) {
|
||||
return null;
|
||||
}
|
||||
final credentials = googleapis_auth.AccessCredentials(
|
||||
googleapis_auth.AccessToken(
|
||||
final gapis.AccessCredentials credentials = gapis.AccessCredentials(
|
||||
gapis.AccessToken(
|
||||
'Bearer',
|
||||
oathTokenString,
|
||||
// We don't know when the token expires, so we assume "never"
|
||||
DateTime.now().toUtc().add(Duration(days: 365)),
|
||||
DateTime.now().toUtc().add(const Duration(days: 365)),
|
||||
),
|
||||
null, // We don't have a refreshToken
|
||||
debugScopes ?? this.scopes,
|
||||
debugScopes ?? scopes,
|
||||
);
|
||||
|
||||
return googleapis_auth.authenticatedClient(http.Client(), credentials);
|
||||
return gapis.authenticatedClient(http.Client(), credentials);
|
||||
}
|
||||
}
|
||||
|
@ -6,22 +6,21 @@
|
||||
|
||||
name: extension_google_sign_in_as_googleapis_auth
|
||||
description: A bridge package between google_sign_in and googleapis_auth, to create Authenticated Clients from google_sign_in user credentials.
|
||||
version: 2.0.0
|
||||
homepage: https://github.com/flutter/plugins/google_sign_in/extension_google_sign_in_as_googleapis_auth
|
||||
version: 2.0.1
|
||||
repository: https://github.com/flutter/packages/tree/master/packages/extension_google_sign_in_as_googleapis_auth
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
google_sign_in: ^5.0.0
|
||||
googleapis_auth: ^1.0.0
|
||||
meta: ^1.3.0
|
||||
http: ^0.13.0
|
||||
meta: ^1.3.0
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: ^1.10.0
|
||||
test: ^1.16.3
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
pedantic: ^1.10.0
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0-259.9.beta <3.0.0"
|
||||
|
@ -5,37 +5,42 @@
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:googleapis_auth/auth.dart' as auth;
|
||||
import 'package:googleapis_auth/auth.dart' as gapis;
|
||||
import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:test/fake.dart';
|
||||
|
||||
const SOME_FAKE_ACCESS_TOKEN = 'this-is-something-not-null';
|
||||
const DEBUG_FAKE_SCOPES = <String>['some-scope', 'another-scope'];
|
||||
const SIGN_IN_FAKE_SCOPES = <String>['some-scope', 'another-scope'];
|
||||
const String SOME_FAKE_ACCESS_TOKEN = 'this-is-something-not-null';
|
||||
const List<String> DEBUG_FAKE_SCOPES = <String>['some-scope', 'another-scope'];
|
||||
const List<String> SIGN_IN_FAKE_SCOPES = <String>[
|
||||
'some-scope',
|
||||
'another-scope'
|
||||
];
|
||||
|
||||
class FakeGoogleSignIn extends Fake implements GoogleSignIn {
|
||||
@override
|
||||
final List<String> scopes = SIGN_IN_FAKE_SCOPES;
|
||||
}
|
||||
|
||||
class FakeGoogleSignInAuthentication extends Fake
|
||||
implements GoogleSignInAuthentication {
|
||||
@override
|
||||
final String accessToken = SOME_FAKE_ACCESS_TOKEN;
|
||||
}
|
||||
|
||||
void main() {
|
||||
GoogleSignIn signIn = FakeGoogleSignIn();
|
||||
final authMock = FakeGoogleSignInAuthentication();
|
||||
final GoogleSignIn signIn = FakeGoogleSignIn();
|
||||
final FakeGoogleSignInAuthentication authMock =
|
||||
FakeGoogleSignInAuthentication();
|
||||
|
||||
test('authenticatedClient returns an authenticated client', () async {
|
||||
final client = await signIn.authenticatedClient(
|
||||
final gapis.AuthClient client = (await signIn.authenticatedClient(
|
||||
debugAuthentication: authMock,
|
||||
);
|
||||
expect(client, isA<auth.AuthClient>());
|
||||
))!;
|
||||
expect(client, isA<gapis.AuthClient>());
|
||||
});
|
||||
|
||||
test('authenticatedClient uses GoogleSignIn scopes by default', () async {
|
||||
final client = (await signIn.authenticatedClient(
|
||||
final gapis.AuthClient client = (await signIn.authenticatedClient(
|
||||
debugAuthentication: authMock,
|
||||
))!;
|
||||
expect(client.credentials.accessToken.data, equals(SOME_FAKE_ACCESS_TOKEN));
|
||||
@ -44,7 +49,7 @@ void main() {
|
||||
|
||||
test('authenticatedClient returned client contains the passed-in credentials',
|
||||
() async {
|
||||
final client = (await signIn.authenticatedClient(
|
||||
final gapis.AuthClient client = (await signIn.authenticatedClient(
|
||||
debugAuthentication: authMock,
|
||||
debugScopes: DEBUG_FAKE_SCOPES,
|
||||
))!;
|
||||
|
Reference in New Issue
Block a user