Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension_gsi] Update extension to support gsi 5 and 6. #3235

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.9

* Makes the extension compatible with `google_sign_in` version `^5.0.0` and `^6.0.0`.
* Fixes a small typo in the code (`oath` -> `oauth`).
* Updates example app to use `google_sign_in: ^6.0.0`.

## 2.0.8

* Updates links for the merge of flutter/plugins into flutter/packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final GoogleSignIn _googleSignIn = GoogleSignIn(
void main() {
runApp(
const MaterialApp(
title: 'Google Sign In',
title: 'Google Sign In + googleapis',
home: SignInDemo(),
),
);
Expand Down Expand Up @@ -149,7 +149,7 @@ class SignInDemoState extends State<SignInDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Google Sign In'),
title: const Text('Google Sign In + googleapis'),
),
body: ConstrainedBox(
constraints: const BoxConstraints.expand(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ dependencies:
path: ../
flutter:
sdk: flutter
google_sign_in: ^5.1.0
googleapis: ^5.0.1
google_sign_in: ^6.0.0
googleapis: ^10.1.0
googleapis_auth: ^1.1.0

dev_dependencies:
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

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

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

<!-- Favicon -->
Expand All @@ -37,75 +37,30 @@

<!-- Google Sign In configuration -->
<meta name="google-signin-client_id" content="[YOUR_OAUTH_2_CLIENT_ID_FOR_WEB]" />
<title>Google Sign-in Example</title>
<title>Google Sign In + googleapis</title>

<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}

if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
}
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});

// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
}
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "example",
"short_name": "example",
"name": "Google Sign In + googleapis",
"short_name": "gsi+googleapis",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"description": "The Google Sign In example app, using the googleapis package.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ extension GoogleApisGoogleSignInAuth on GoogleSignIn {
}) async {
final GoogleSignInAuthentication? auth =
debugAuthentication ?? await currentUser?.authentication;
final String? oathTokenString = auth?.accessToken;
if (oathTokenString == null) {
final String? oauthTokenString = auth?.accessToken;
if (oauthTokenString == null) {
return null;
}
final gapis.AccessCredentials credentials = gapis.AccessCredentials(
gapis.AccessToken(
'Bearer',
oathTokenString,
oauthTokenString,
// TODO(kevmoo): Use the correct value once it's available from authentication
// See https://github.com/flutter/flutter/issues/80905
DateTime.now().toUtc().add(const Duration(days: 365)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.8
version: 2.0.9

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -17,7 +17,7 @@ environment:
dependencies:
flutter:
sdk: flutter
google_sign_in: ^5.0.0
google_sign_in: ">=5.0.0 <7.0.0"
googleapis_auth: ^1.1.0
http: ^0.13.0
meta: ^1.3.0
Expand Down