Skip to content

Commit af5906b

Browse files
authored
[extension_gsi] Update extension to support gsi 5 and 6. (flutter#3235)
* [extension_gsi] Support google_sign_in ^5.0.0 and ^6.0.0. * Update example to google_sign_in ^6.0.0 Also update the index.html to the latest style, and add some changes to make this build distinguishable from the default one (the + googleapis bits) * Fix typo: oath -> oauth * Update CHANGELOG.
1 parent 195f4e8 commit af5906b

File tree

8 files changed

+39
-80
lines changed

8 files changed

+39
-80
lines changed

packages/extension_google_sign_in_as_googleapis_auth/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.0.9
2+
3+
* Makes the extension compatible with `google_sign_in` version `^5.0.0` and `^6.0.0`.
4+
* Fixes a small typo in the code (`oath` -> `oauth`).
5+
* Updates example app to use `google_sign_in: ^6.0.0`.
6+
17
## 2.0.8
28

39
* Updates links for the merge of flutter/plugins into flutter/packages.

packages/extension_google_sign_in_as_googleapis_auth/example/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
/build/
3333

3434
# Web related
35-
lib/generated_plugin_registrant.dart
3635

3736
# Symbolication related
3837
app.*.symbols

packages/extension_google_sign_in_as_googleapis_auth/example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final GoogleSignIn _googleSignIn = GoogleSignIn(
1919
void main() {
2020
runApp(
2121
const MaterialApp(
22-
title: 'Google Sign In',
22+
title: 'Google Sign In + googleapis',
2323
home: SignInDemo(),
2424
),
2525
);
@@ -149,7 +149,7 @@ class SignInDemoState extends State<SignInDemo> {
149149
Widget build(BuildContext context) {
150150
return Scaffold(
151151
appBar: AppBar(
152-
title: const Text('Google Sign In'),
152+
title: const Text('Google Sign In + googleapis'),
153153
),
154154
body: ConstrainedBox(
155155
constraints: const BoxConstraints.expand(),

packages/extension_google_sign_in_as_googleapis_auth/example/pubspec.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ dependencies:
1616
path: ../
1717
flutter:
1818
sdk: flutter
19-
google_sign_in: ^5.1.0
20-
googleapis: ^5.0.1
19+
google_sign_in: ^6.0.0
20+
googleapis: ^10.1.0
2121
googleapis_auth: ^1.1.0
2222

2323
dev_dependencies:
24-
flutter_lints: ^1.0.0
2524
flutter_test:
2625
sdk: flutter
2726

packages/extension_google_sign_in_as_googleapis_auth/example/web/index.html

Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
<meta charset="UTF-8">
2424
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
25-
<meta name="description" content="A new Flutter project.">
25+
<meta name="description" content="The Google Sign In example app, using the googleapis package.">
2626

2727
<!-- iOS meta tags & icons -->
2828
<meta name="apple-mobile-web-app-capable" content="yes">
2929
<meta name="apple-mobile-web-app-status-bar-style" content="black">
30-
<meta name="apple-mobile-web-app-title" content="example">
30+
<meta name="apple-mobile-web-app-title" content="Google Sign In + googleapis">
3131
<link rel="apple-touch-icon" href="icons/Icon-192.png">
3232

3333
<!-- Favicon -->
@@ -37,75 +37,30 @@
3737

3838
<!-- Google Sign In configuration -->
3939
<meta name="google-signin-client_id" content="[YOUR_OAUTH_2_CLIENT_ID_FOR_WEB]" />
40-
<title>Google Sign-in Example</title>
40+
<title>Google Sign In + googleapis</title>
41+
42+
<script>
43+
// The value below is injected by flutter build, do not touch.
44+
var serviceWorkerVersion = null;
45+
</script>
46+
<!-- This script adds the flutter initialization JS code -->
47+
<script src="flutter.js" defer></script>
4148
</head>
4249
<body>
43-
<!-- This script installs service_worker.js to provide PWA functionality to
44-
application. For more information, see:
45-
https://developers.google.com/web/fundamentals/primers/service-workers -->
4650
<script>
47-
var serviceWorkerVersion = null;
48-
var scriptLoaded = false;
49-
function loadMainDartJs() {
50-
if (scriptLoaded) {
51-
return;
52-
}
53-
scriptLoaded = true;
54-
var scriptTag = document.createElement('script');
55-
scriptTag.src = 'main.dart.js';
56-
scriptTag.type = 'application/javascript';
57-
document.body.append(scriptTag);
58-
}
59-
60-
if ('serviceWorker' in navigator) {
61-
// Service workers are supported. Use them.
62-
window.addEventListener('load', function () {
63-
// Wait for registration to finish before dropping the <script> tag.
64-
// Otherwise, the browser will load the script multiple times,
65-
// potentially different versions.
66-
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
67-
navigator.serviceWorker.register(serviceWorkerUrl)
68-
.then((reg) => {
69-
function waitForActivation(serviceWorker) {
70-
serviceWorker.addEventListener('statechange', () => {
71-
if (serviceWorker.state == 'activated') {
72-
console.log('Installed new service worker.');
73-
loadMainDartJs();
74-
}
75-
});
76-
}
77-
if (!reg.active && (reg.installing || reg.waiting)) {
78-
// No active web worker and we have installed or are installing
79-
// one for the first time. Simply wait for it to activate.
80-
waitForActivation(reg.installing || reg.waiting);
81-
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
82-
// When the app updates the serviceWorkerVersion changes, so we
83-
// need to ask the service worker to update.
84-
console.log('New service worker available.');
85-
reg.update();
86-
waitForActivation(reg.installing);
87-
} else {
88-
// Existing service worker is still good.
89-
console.log('Loading app from service worker.');
90-
loadMainDartJs();
91-
}
51+
window.addEventListener('load', function(ev) {
52+
// Download main.dart.js
53+
_flutter.loader.loadEntrypoint({
54+
serviceWorker: {
55+
serviceWorkerVersion: serviceWorkerVersion,
56+
},
57+
onEntrypointLoaded: function(engineInitializer) {
58+
engineInitializer.initializeEngine().then(function(appRunner) {
59+
appRunner.runApp();
9260
});
93-
94-
// If service worker doesn't succeed in a reasonable amount of time,
95-
// fallback to plaint <script> tag.
96-
setTimeout(() => {
97-
if (!scriptLoaded) {
98-
console.warn(
99-
'Failed to load app from service worker. Falling back to plain <script> tag.',
100-
);
101-
loadMainDartJs();
102-
}
103-
}, 4000);
61+
}
10462
});
105-
} else {
106-
// Service workers not supported. Just drop the <script> tag.
107-
loadMainDartJs();
108-
}
63+
});
10964
</script>
11065
</body>
11166
</html>

packages/extension_google_sign_in_as_googleapis_auth/example/web/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "example",
3-
"short_name": "example",
2+
"name": "Google Sign In + googleapis",
3+
"short_name": "gsi+googleapis",
44
"start_url": ".",
55
"display": "standalone",
66
"background_color": "#0175C2",
77
"theme_color": "#0175C2",
8-
"description": "A new Flutter project.",
8+
"description": "The Google Sign In example app, using the googleapis package.",
99
"orientation": "portrait-primary",
1010
"prefer_related_applications": false,
1111
"icons": [

packages/extension_google_sign_in_as_googleapis_auth/lib/extension_google_sign_in_as_googleapis_auth.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ extension GoogleApisGoogleSignInAuth on GoogleSignIn {
1919
}) async {
2020
final GoogleSignInAuthentication? auth =
2121
debugAuthentication ?? await currentUser?.authentication;
22-
final String? oathTokenString = auth?.accessToken;
23-
if (oathTokenString == null) {
22+
final String? oauthTokenString = auth?.accessToken;
23+
if (oauthTokenString == null) {
2424
return null;
2525
}
2626
final gapis.AccessCredentials credentials = gapis.AccessCredentials(
2727
gapis.AccessToken(
2828
'Bearer',
29-
oathTokenString,
29+
oauthTokenString,
3030
// TODO(kevmoo): Use the correct value once it's available from authentication
3131
// See https://github.com/flutter/flutter/issues/80905
3232
DateTime.now().toUtc().add(const Duration(days: 365)),

packages/extension_google_sign_in_as_googleapis_auth/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name: extension_google_sign_in_as_googleapis_auth
88
description: A bridge package between google_sign_in and googleapis_auth, to create Authenticated Clients from google_sign_in user credentials.
99
repository: https://github.com/flutter/packages/tree/main/packages/extension_google_sign_in_as_googleapis_auth
1010
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
11-
version: 2.0.8
11+
version: 2.0.9
1212

1313
environment:
1414
sdk: ">=2.12.0 <3.0.0"
@@ -17,7 +17,7 @@ environment:
1717
dependencies:
1818
flutter:
1919
sdk: flutter
20-
google_sign_in: ^5.0.0
20+
google_sign_in: ">=5.0.0 <7.0.0"
2121
googleapis_auth: ^1.1.0
2222
http: ^0.13.0
2323
meta: ^1.3.0

0 commit comments

Comments
 (0)