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

[google_sign_in] Add server auth code retrieval to gis_client #5358

Merged
merged 4 commits into from
Nov 30, 2023

Conversation

T-P-F
Copy link
Contributor

@T-P-F T-P-F commented Nov 9, 2023

Adds the ability for a Flutter web app to request a server auth code via gis through a web-only method.

Reference docs:

Also: adds a web_only.dart library that allows programmers to call web-only methods conveniently, without having to dive into the Platform.instance (which has a ton of methods that we don't want users to call for sure!), like this:

import 'package:google_sign_in_web/web_only.dart' as web;

/// Renders a web-only Sign-In button.
Widget buildSignInButton({HandleSignInFn? _}) {
  return web.renderButton();
}

Instead of:

Widget buildSignInButton({HandleSignInFn? onPressed}) {
return (GoogleSignInPlatform.instance as web.GoogleSignInPlugin)
.renderButton();
}

Issues

Tests

  • Added tests to ensure plugin calls hit the GIS API when appropriate.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@T-P-F T-P-F requested a review from ditman as a code owner November 9, 2023 06:26
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie or stuartmorgan on the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@ditman
Copy link
Member

ditman commented Nov 9, 2023

Thanks for solving the conflicts with the latest main!

@ditman
Copy link
Member

ditman commented Nov 10, 2023

We'll need 2 reviewers, since this is @T-P-F's first contribution. Pinging @stuartmorgan for when he has a minute!

@T-P-F
Copy link
Contributor Author

T-P-F commented Nov 10, 2023

@ditman thanks for the additions to the PR 🙏

@stuartmorgan
Copy link
Contributor

We'll need 2 reviewers, since this is @T-P-F's first contribution.

FYI this is true for all PRs from contributors who are not Flutter team members (i.e., people with commit access), regardless of whether it's the first PR.

(I'll add this to my review queue.)

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on my end!

(We could add a small section to the README on how to use the web_only library maybe? I'm planning on updating the example app regardless.)

@T-P-F
Copy link
Contributor Author

T-P-F commented Nov 27, 2023

@ditman @stuartmorgan what's a realistic timeline for finishing review of this PR?

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 30, 2023
@auto-submit auto-submit bot merged commit 39678d1 into flutter:main Nov 30, 2023
80 checks passed
@kevmoo
Copy link
Contributor

kevmoo commented Nov 30, 2023

Great fix @T-P-F !! 👏👏👏

@ditman
Copy link
Member

ditman commented Nov 30, 2023

Yay! I need to update the example to use the new user-facing web-only API!

auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Dec 4, 2023
flutter/packages@bc72d15...5d9874f

2023-12-02 [email protected] Roll Flutter from 918e336 to d861ce4 (29 revisions) (flutter/packages#5542)
2023-12-02 [email protected] [gsi_web] Do not initialize CodeClient if scopes are empty. (flutter/packages#5537)
2023-12-01 [email protected] Reenable macOS 13 tests (flutter/packages#5494)
2023-12-01 [email protected] [flutter_image] Adopt code excerpts in README (flutter/packages#5498)
2023-11-30 [email protected] [cross_file] Migrate to pkg:web, bump min SDK to Dart 3.2 (flutter/packages#5520)
2023-11-30 [email protected] [google_maps_flutter] Add support for version 8 of the iOS SDK (flutter/packages#5528)
2023-11-30 [email protected] [pointer_interceptor] Re-land: Add platform interface (flutter/packages#5525)
2023-11-30 [email protected] [google_sign_in] Add server auth code retrieval to gis_client (flutter/packages#5358)
2023-11-30 [email protected] Roll Flutter from 5e5b529 to 918e336 (14 revisions) (flutter/packages#5526)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
HugoOlthof pushed a commit to moneybird/packages that referenced this pull request Dec 13, 2023
…r#5358)

Adds the ability for a Flutter web app to request a server auth code via gis through a web-only method.

Reference docs:
* https://developers.google.com/identity/oauth2/web/guides/use-code-model
* https://developers.google.com/identity/oauth2/web/reference/js-reference#google.accounts.oauth2.initCodeClient

Also: adds a `web_only.dart` library that allows programmers to call web-only methods conveniently, without having to dive into the `Platform.instance` (which has a ton of methods that we don't want users to call for sure!), like this:

```dart
import 'package:google_sign_in_web/web_only.dart' as web;

/// Renders a web-only Sign-In button.
Widget buildSignInButton({HandleSignInFn? _}) {
  return web.renderButton();
}
```

Instead of:

https://github.com/flutter/packages/blob/a6821898bd5a968f8ddafa8ae8e9a8c889caa00a/packages/google_sign_in/google_sign_in/example/lib/src/sign_in_button/web.dart#L12-L15

### Issues

* Fixes flutter/flutter#62474

### Tests

* Added tests to ensure plugin calls hit the GIS API when appropriate.

* [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
* [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities.
* [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
* [x] I signed the [CLA].
* [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
* [x] I listed at least one issue that this PR fixes in the description above.
* [x] I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
* [x] I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style].
* [x] I updated/added relevant documentation (doc comments with ///).
* [x] I added new tests to check the change I am making, or this PR is [test-exempt].
* [x] All existing and new tests are passing.
@wreppun
Copy link

wreppun commented Mar 2, 2024

Looks like there's no way (AFAIK) to modify the scopes for serverAuthCode retrieval (to allow incremental authorization)?

Once the scopes are set in initWithParams, there isn't even a way to change them by re-initializing the entire _gisClient (because there's no way to re-initialize the _gisClient in google_sign_in_web).

Is incremental authorization possible at this moment?

Would the preferred approach be to accept an optional list of scopes in requestServerAuthCode and to then re-init the _codeClient within that method (if scopes are present)?

Use case:

  • User signs in, with no required scopes (authentication only)
  • User wants to use a feature which requires a serverAuthCode
  • User is prompted for authorization for that specific service/permissions (currently not possible, AFAIK)

Happy to split this out into a bug report; just not sure if I'm missing something here.

@wreppun
Copy link

wreppun commented Mar 2, 2024

Whoops, just found this: flutter/flutter#139406

arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…r#5358)

Adds the ability for a Flutter web app to request a server auth code via gis through a web-only method.

Reference docs:
* https://developers.google.com/identity/oauth2/web/guides/use-code-model
* https://developers.google.com/identity/oauth2/web/reference/js-reference#google.accounts.oauth2.initCodeClient

Also: adds a `web_only.dart` library that allows programmers to call web-only methods conveniently, without having to dive into the `Platform.instance` (which has a ton of methods that we don't want users to call for sure!), like this:

```dart
import 'package:google_sign_in_web/web_only.dart' as web;

/// Renders a web-only Sign-In button.
Widget buildSignInButton({HandleSignInFn? _}) {
  return web.renderButton();
}
```

Instead of:

https://github.com/flutter/packages/blob/a6821898bd5a968f8ddafa8ae8e9a8c889caa00a/packages/google_sign_in/google_sign_in/example/lib/src/sign_in_button/web.dart#L12-L15

### Issues

* Fixes flutter/flutter#62474

### Tests

* Added tests to ensure plugin calls hit the GIS API when appropriate.

* [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
* [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities.
* [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
* [x] I signed the [CLA].
* [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
* [x] I listed at least one issue that this PR fixes in the description above.
* [x] I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
* [x] I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style].
* [x] I updated/added relevant documentation (doc comments with ///).
* [x] I added new tests to check the change I am making, or this PR is [test-exempt].
* [x] All existing and new tests are passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: google_sign_in platform-web
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Google Sign In 4.5.1 - ServerAuthCode returns null value for Web
5 participants