Visitar URL original
[extension_google_sign_in_as_googleapis_auth] Move from flutter/plugins. by ditman · Pull Request #301 · flutter/packages · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f78546c
[google_sign_in] Bridge google_sign_in and googleapis. (#2824)
ditman Jul 14, 2020
fbceb5f
Make package:e2e a relative reference (#2889)
dnfield Jul 24, 2020
c04e936
Rename e2e -> integration_test (#2918)
dnfield Aug 19, 2020
dc9e48e
Standardize LICENSE body text formatting (#2992)
stuartmorgan-g Sep 3, 2020
698ca3c
Add deprecation suppression for plugins marked with -Werror (#3072)
xster Sep 23, 2020
878c10a
Update android sdk version to 29 for all mobile plugins. (#3042)
Oct 14, 2020
820b186
[d-g] Update Flutter SDK constraint (#3321)
mit-mit Dec 11, 2020
90adf95
Fix outdated links across a number of markdown files (#3276)
kevmoo Dec 18, 2020
a77819f
Update obsolete button refs in plugin examples (#3395)
HansMuller Jan 7, 2021
a24c98a
Update pubspecs (#3534)
mit-mit Feb 10, 2021
0621213
Added comment about path depenendencies (#3542)
jonasfj Feb 12, 2021
abb8933
[extension_google_sign_in_as_googleapis_auth] Migrate to null safety …
stuartmorgan-g Feb 26, 2021
69413ad
Move to flutter/packages
ditman Mar 5, 2021
0796f29
Merge branch 'master' of /usr/local/google/home/dit/github/moving-ext…
ditman Mar 5, 2021
ab9eb3b
Make analyzer happy.
ditman Mar 5, 2021
1d167e7
Ignore generated files from example
ditman Mar 5, 2021
c05c680
Import from googleapis_auth.dart
ditman Mar 8, 2021
52bace7
Bump version and changelog.
ditman Mar 8, 2021
8256805
Do not bump major version
ditman Mar 8, 2021
eba7f33
Update example to sound null safety
ditman Mar 8, 2021
42ca626
Update README
ditman Mar 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make analyzer happy.
  • Loading branch information
ditman committed Mar 5, 2021
commit ab9eb3b5e57b7876c95c255d7381eeeb0b958a89
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ 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
# See https://dart.dev/tools/pub/dependencies#version-constraints
# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment thread
ditman marked this conversation as resolved.
Resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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,
))!;
Expand Down