From 310855ab2f8498e6ae912a45755e6701c643c9d5 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 27 Nov 2023 14:09:57 -0800 Subject: [PATCH 1/4] [extension_google_sign_in_as_googleapis_auth] Adopt code excerpts in README --- .../CHANGELOG.md | 3 ++- .../README.md | 8 ++++-- .../example/lib/readme_excerpts.dart | 26 +++++++++++++++++++ .../pubspec.yaml | 2 +- script/configs/temp_exclude_excerpt.yaml | 1 - 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart diff --git a/packages/extension_google_sign_in_as_googleapis_auth/CHANGELOG.md b/packages/extension_google_sign_in_as_googleapis_auth/CHANGELOG.md index 682ad3a146f..4d98d664590 100644 --- a/packages/extension_google_sign_in_as_googleapis_auth/CHANGELOG.md +++ b/packages/extension_google_sign_in_as_googleapis_auth/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 2.0.12 * Updates minimum supported SDK version to Flutter 3.10/Dart 3.0. +* Updates README to improve example of using google_sign_in plugin with the `googleapis` package. ## 2.0.11 diff --git a/packages/extension_google_sign_in_as_googleapis_auth/README.md b/packages/extension_google_sign_in_as_googleapis_auth/README.md index 2f8a376c47d..5a9dae6b8d4 100644 --- a/packages/extension_google_sign_in_as_googleapis_auth/README.md +++ b/packages/extension_google_sign_in_as_googleapis_auth/README.md @@ -8,6 +8,7 @@ This package is implemented as an [extension method](https://dart.dev/guides/lan In order to use it, you need to add a `dependency` to your `pubspec.yaml`. Then, wherever you're importing `package:google_sign_in/google_sign_in.dart`, add the following: + ```dart import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart'; ``` @@ -16,9 +17,12 @@ From that moment on, your `GoogleSignIn` instance will have an additional `Futur That object can then be used to create instances of `googleapis` API clients: + ```dart -final peopleApi = PeopleApi((await _googleSignIn.authenticatedClient())!); -final response = await peopleApi.people.connections.list( +final PeopleServiceApi peopleApi = + PeopleServiceApi((await _googleSignIn.authenticatedClient())!); +final ListConnectionsResponse response = + await peopleApi.people.connections.list( 'people/me', personFields: 'names', ); diff --git a/packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart b/packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart new file mode 100644 index 00000000000..3ba2eb3a21e --- /dev/null +++ b/packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// #docregion Import +import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart'; +// #enddocregion Import +import 'package:google_sign_in/google_sign_in.dart'; +import 'package:googleapis/people/v1.dart'; + +final GoogleSignIn _googleSignIn = GoogleSignIn(); + +/// Demonstrates using GoogleSignIn authenticated client to use `googleapis` API clients +Future createAPIClient() async { + // #docregion CreateAPIClient + final PeopleServiceApi peopleApi = + PeopleServiceApi((await _googleSignIn.authenticatedClient())!); + final ListConnectionsResponse response = + await peopleApi.people.connections.list( + 'people/me', + personFields: 'names', + ); + // #enddocregion CreateAPIClient + + return response; +} diff --git a/packages/extension_google_sign_in_as_googleapis_auth/pubspec.yaml b/packages/extension_google_sign_in_as_googleapis_auth/pubspec.yaml index 4d5e1a06b3f..3adbd967744 100644 --- a/packages/extension_google_sign_in_as_googleapis_auth/pubspec.yaml +++ b/packages/extension_google_sign_in_as_googleapis_auth/pubspec.yaml @@ -8,7 +8,7 @@ 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. repository: https://github.com/flutter/packages/tree/main/packages/extension_google_sign_in_as_googleapis_auth issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+extension_google_sign_in_as_googleapis_auth%22 -version: 2.0.11 +version: 2.0.12 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/script/configs/temp_exclude_excerpt.yaml b/script/configs/temp_exclude_excerpt.yaml index c1fe3e9aa86..915b97c5bb0 100644 --- a/script/configs/temp_exclude_excerpt.yaml +++ b/script/configs/temp_exclude_excerpt.yaml @@ -7,7 +7,6 @@ # https://github.com/flutter/flutter/issues/102679 - css_colors - espresso -- extension_google_sign_in_as_googleapis_auth - flutter_image - go_router_builder - google_sign_in/google_sign_in From 4d1461bb492b57e41d104d60dd742ad6cbccbff3 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 4 Dec 2023 17:45:04 -0800 Subject: [PATCH 2/4] Fix dead link in README --- packages/extension_google_sign_in_as_googleapis_auth/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension_google_sign_in_as_googleapis_auth/README.md b/packages/extension_google_sign_in_as_googleapis_auth/README.md index 5a9dae6b8d4..462be60210c 100644 --- a/packages/extension_google_sign_in_as_googleapis_auth/README.md +++ b/packages/extension_google_sign_in_as_googleapis_auth/README.md @@ -1,6 +1,6 @@ # extension_google_sign_in_as_googleapis_auth -A bridge package between Flutter's [`google_sign_in` plugin](https://pub.dev/packages/google_sign_in) and Dart's [`googleapis` package](https://pub.dev/packages/googleapis), that is able to create [`googleapis_auth`-like `AuthClient` instances](https://pub.dev/documentation/googleapis_auth/latest/googleapis_auth.auth/AuthClient-class.html) directly from the `GoogleSignIn` plugin. +A bridge package between Flutter's [`google_sign_in` plugin](https://pub.dev/packages/google_sign_in) and Dart's [`googleapis` package](https://pub.dev/packages/googleapis), that is able to create [`googleapis_auth`-like `AuthClient` instances](https://pub.dev/documentation/googleapis_auth/latest/googleapis_auth/AuthClient-class.html) directly from the `GoogleSignIn` plugin. ## Usage From cd9106b5d7dc7eff53d36729cdf8970b8a2e0618 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 6 Dec 2023 14:04:18 -0800 Subject: [PATCH 3/4] Get code excerpts from example/lib/main instead of creating new file --- .../README.md | 14 +++++++--- .../example/lib/main.dart | 4 +++ .../example/lib/readme_excerpts.dart | 26 ------------------- 3 files changed, 14 insertions(+), 30 deletions(-) delete mode 100644 packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart diff --git a/packages/extension_google_sign_in_as_googleapis_auth/README.md b/packages/extension_google_sign_in_as_googleapis_auth/README.md index 462be60210c..ddc66711d40 100644 --- a/packages/extension_google_sign_in_as_googleapis_auth/README.md +++ b/packages/extension_google_sign_in_as_googleapis_auth/README.md @@ -8,7 +8,7 @@ This package is implemented as an [extension method](https://dart.dev/guides/lan In order to use it, you need to add a `dependency` to your `pubspec.yaml`. Then, wherever you're importing `package:google_sign_in/google_sign_in.dart`, add the following: - + ```dart import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart'; ``` @@ -17,10 +17,16 @@ From that moment on, your `GoogleSignIn` instance will have an additional `Futur That object can then be used to create instances of `googleapis` API clients: - + ```dart -final PeopleServiceApi peopleApi = - PeopleServiceApi((await _googleSignIn.authenticatedClient())!); +// Retrieve an [auth.AuthClient] from the current [GoogleSignIn] instance. +final auth.AuthClient? client = await _googleSignIn.authenticatedClient(); + +assert(client != null, 'Authenticated client missing!'); + +// Prepare a People Service authenticated client. +final PeopleServiceApi peopleApi = PeopleServiceApi(client!); +// Retrieve a list of the `names` of my `connections` final ListConnectionsResponse response = await peopleApi.people.connections.list( 'people/me', diff --git a/packages/extension_google_sign_in_as_googleapis_auth/example/lib/main.dart b/packages/extension_google_sign_in_as_googleapis_auth/example/lib/main.dart index 8e982ace225..369135371ed 100644 --- a/packages/extension_google_sign_in_as_googleapis_auth/example/lib/main.dart +++ b/packages/extension_google_sign_in_as_googleapis_auth/example/lib/main.dart @@ -4,7 +4,9 @@ import 'dart:async'; +// #docregion Import import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart'; +// #enddocregion Import import 'package:flutter/material.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:googleapis/people/v1.dart'; @@ -58,6 +60,7 @@ class SignInDemoState extends State { _contactText = 'Loading contact info...'; }); +// #docregion CreateAPIClient // Retrieve an [auth.AuthClient] from the current [GoogleSignIn] instance. final auth.AuthClient? client = await _googleSignIn.authenticatedClient(); @@ -71,6 +74,7 @@ class SignInDemoState extends State { 'people/me', personFields: 'names', ); + // #enddocregion CreateAPIClient final String? firstNamedContactName = _pickFirstNamedContact(response.connections); diff --git a/packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart b/packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart deleted file mode 100644 index 3ba2eb3a21e..00000000000 --- a/packages/extension_google_sign_in_as_googleapis_auth/example/lib/readme_excerpts.dart +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// #docregion Import -import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart'; -// #enddocregion Import -import 'package:google_sign_in/google_sign_in.dart'; -import 'package:googleapis/people/v1.dart'; - -final GoogleSignIn _googleSignIn = GoogleSignIn(); - -/// Demonstrates using GoogleSignIn authenticated client to use `googleapis` API clients -Future createAPIClient() async { - // #docregion CreateAPIClient - final PeopleServiceApi peopleApi = - PeopleServiceApi((await _googleSignIn.authenticatedClient())!); - final ListConnectionsResponse response = - await peopleApi.people.connections.list( - 'people/me', - personFields: 'names', - ); - // #enddocregion CreateAPIClient - - return response; -} From c83b062158e48844fcb63d6855168ce411e18a49 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 8 Dec 2023 17:20:02 -0800 Subject: [PATCH 4/4] Update temp_exclude_excerpt --- script/configs/temp_exclude_excerpt.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/script/configs/temp_exclude_excerpt.yaml b/script/configs/temp_exclude_excerpt.yaml index 915b97c5bb0..deeb0e9968f 100644 --- a/script/configs/temp_exclude_excerpt.yaml +++ b/script/configs/temp_exclude_excerpt.yaml @@ -7,7 +7,6 @@ # https://github.com/flutter/flutter/issues/102679 - css_colors - espresso -- flutter_image - go_router_builder - google_sign_in/google_sign_in - image_picker_for_web