-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[google_sign_in] Add a method to clear auth tokens #9846
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
base: main
Are you sure you want to change the base?
[google_sign_in] Add a method to clear auth tokens #9846
Conversation
Adds a new `clearAuthCache` method to the `google_sign_in` plugin. This method allows developers to clear the auth cache for a signed-in user. The implementation is provided for the Android and Web platforms. On Android, it calls `AuthorizationClient.clearToken`. On Web, it removes the matching entry from an in-memory cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new clearAuthorizationToken
method across all layers of the google_sign_in
plugin. This allows developers to manually clear a cached authorization token if it becomes invalid. The implementation is handled natively on Android, is a no-op on iOS (as the SDK handles it), and clears a local cache on the web. The changes include updates to the platform interface, implementations for each platform, and corresponding tests and documentation.
My review identifies a critical issue with dependency_overrides
that must be removed before merging. I've also suggested improvements to the Android tests for better coverage and a minor code style improvement in the Android implementation to avoid type shadowing.
...ign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java
Outdated
Show resolved
Hide resolved
..._sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java
Outdated
Show resolved
Hide resolved
The pathified unit test failure in |
A copy of @stuartmorgan-g change at flutter/packages#9805 > Initial attempt at adding guidance for GCAfGH to try cut down on the behavior observed so far that it: > - Almost always includes generic praise for the PR, which is unhelpful since the agent has no context for evaluating what PRs we actually want (see [this particularly problematic example](flutter/packages#9795 (review))) > - Appears to trust PR descriptions. E.g., recently praising a PR that was missing tests of most of the PR, but had a PR description saying it included extensive testing, as being extremely well tested. Here are examples of summaries from the packages repo before and after this change: Before (praise like "great refactoring effort", "significantly improves the modularity and maintainability", "extensive documentation updates are also a major improvement"): > This pull request is a great refactoring effort. Moving the ProxyAPI generation logic into a dedicated helper file (`proxy_api_generator_helper.dart`) significantly improves the modularity and maintainability of the Dart generator. The extensive documentation updates are also a major improvement, making the concepts around ProxyAPIs much clearer for developers. flutter/packages#9756 After (drier, describing the actual change without making normative evaluation): > This pull request introduces a new `clearAuthorizationToken` method across all layers of the `google_sign_in` plugin. This allows developers to manually clear a cached authorization token if it becomes invalid. The implementation is handled natively on Android, is a no-op on iOS (as the SDK handles it), and clears a local cache on the web. The changes include updates to the platform interface, implementations for each platform, and corresponding tests and documentation. flutter/packages#9846 (review) ## Pre-launch Checklist - [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 [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [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] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
A copy of @stuartmorgan-g change at flutter/packages#9805 > Initial attempt at adding guidance for GCAfGH to try cut down on the behavior observed so far that it: > - Almost always includes generic praise for the PR, which is unhelpful since the agent has no context for evaluating what PRs we actually want (see [this particularly problematic example](flutter/packages#9795 (review))) > - Appears to trust PR descriptions. E.g., recently praising a PR that was missing tests of most of the PR, but had a PR description saying it included extensive testing, as being extremely well tested. Here are examples of summaries from the packages repo before and after this change: Before (praise like "great refactoring effort", "significantly improves the modularity and maintainability", "extensive documentation updates are also a major improvement"): > This pull request is a great refactoring effort. Moving the ProxyAPI generation logic into a dedicated helper file (`proxy_api_generator_helper.dart`) significantly improves the modularity and maintainability of the Dart generator. The extensive documentation updates are also a major improvement, making the concepts around ProxyAPIs much clearer for developers. flutter/packages#9756 After (drier, describing the actual change without making normative evaluation): > This pull request introduces a new `clearAuthorizationToken` method across all layers of the `google_sign_in` plugin. This allows developers to manually clear a cached authorization token if it becomes invalid. The implementation is handled natively on Android, is a no-op on iOS (as the SDK handles it), and clears a local cache on the web. The changes include updates to the platform interface, implementations for each platform, and corresponding tests and documentation. flutter/packages#9846 (review) ## Pre-launch Checklist - [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 [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [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] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
A copy of @stuartmorgan-g change at flutter/packages#9805 > Initial attempt at adding guidance for GCAfGH to try cut down on the behavior observed so far that it: > - Almost always includes generic praise for the PR, which is unhelpful since the agent has no context for evaluating what PRs we actually want (see [this particularly problematic example](flutter/packages#9795 (review))) > - Appears to trust PR descriptions. E.g., recently praising a PR that was missing tests of most of the PR, but had a PR description saying it included extensive testing, as being extremely well tested. Here are examples of summaries from the packages repo before and after this change: Before (praise like "great refactoring effort", "significantly improves the modularity and maintainability", "extensive documentation updates are also a major improvement"): > This pull request is a great refactoring effort. Moving the ProxyAPI generation logic into a dedicated helper file (`proxy_api_generator_helper.dart`) significantly improves the modularity and maintainability of the Dart generator. The extensive documentation updates are also a major improvement, making the concepts around ProxyAPIs much clearer for developers. flutter/packages#9756 After (drier, describing the actual change without making normative evaluation): > This pull request introduces a new `clearAuthorizationToken` method across all layers of the `google_sign_in` plugin. This allows developers to manually clear a cached authorization token if it becomes invalid. The implementation is handled natively on Android, is a no-op on iOS (as the SDK handles it), and clears a local cache on the web. The changes include updates to the platform interface, implementations for each platform, and corresponding tests and documentation. flutter/packages#9846 (review) ## Pre-launch Checklist - [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 [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [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] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…74000) A copy of @stuartmorgan-g change at flutter/packages#9805 > Initial attempt at adding guidance for GCAfGH to try cut down on the behavior observed so far that it: > - Almost always includes generic praise for the PR, which is unhelpful since the agent has no context for evaluating what PRs we actually want (see [this particularly problematic example](flutter/packages#9795 (review))) > - Appears to trust PR descriptions. E.g., recently praising a PR that was missing tests of most of the PR, but had a PR description saying it included extensive testing, as being extremely well tested. Here are examples of summaries from the packages repo before and after this change: Before (praise like "great refactoring effort", "significantly improves the modularity and maintainability", "extensive documentation updates are also a major improvement"): > This pull request is a great refactoring effort. Moving the ProxyAPI generation logic into a dedicated helper file (`proxy_api_generator_helper.dart`) significantly improves the modularity and maintainability of the Dart generator. The extensive documentation updates are also a major improvement, making the concepts around ProxyAPIs much clearer for developers. flutter/packages#9756 After (drier, describing the actual change without making normative evaluation): > This pull request introduces a new `clearAuthorizationToken` method across all layers of the `google_sign_in` plugin. This allows developers to manually clear a cached authorization token if it becomes invalid. The implementation is handled natively on Android, is a no-op on iOS (as the SDK handles it), and clears a local cache on the web. The changes include updates to the platform interface, implementations for each platform, and corresponding tests and documentation. flutter/packages#9846 (review) ## Pre-launch Checklist - [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 [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [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] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…74000) A copy of @stuartmorgan-g change at flutter/packages#9805 > Initial attempt at adding guidance for GCAfGH to try cut down on the behavior observed so far that it: > - Almost always includes generic praise for the PR, which is unhelpful since the agent has no context for evaluating what PRs we actually want (see [this particularly problematic example](flutter/packages#9795 (review))) > - Appears to trust PR descriptions. E.g., recently praising a PR that was missing tests of most of the PR, but had a PR description saying it included extensive testing, as being extremely well tested. Here are examples of summaries from the packages repo before and after this change: Before (praise like "great refactoring effort", "significantly improves the modularity and maintainability", "extensive documentation updates are also a major improvement"): > This pull request is a great refactoring effort. Moving the ProxyAPI generation logic into a dedicated helper file (`proxy_api_generator_helper.dart`) significantly improves the modularity and maintainability of the Dart generator. The extensive documentation updates are also a major improvement, making the concepts around ProxyAPIs much clearer for developers. flutter/packages#9756 After (drier, describing the actual change without making normative evaluation): > This pull request introduces a new `clearAuthorizationToken` method across all layers of the `google_sign_in` plugin. This allows developers to manually clear a cached authorization token if it becomes invalid. The implementation is handled natively on Android, is a no-op on iOS (as the SDK handles it), and clears a local cache on the web. The changes include updates to the platform interface, implementations for each platform, and corresponding tests and documentation. flutter/packages#9846 (review) ## Pre-launch Checklist - [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 [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [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] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay the ios changes lgtm.
@@ -363,6 +363,29 @@ class AuthenticationResults { | |||
final AuthenticationTokenData authenticationTokens; | |||
} | |||
|
|||
/// Parameters for the clearAuthorizationTokens method. | |||
@immutable | |||
class ClearAuthorizationTokensParams { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: do we always need to introduce an additional type for parameters? Is it specifically for pigeon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to mark the class final
(so no need for the runtimeType check in ==
), or using an extension type?
Adds a new
clearAuthorizationToken
method to all layers of the plugin stack, allowing for removing a token from the cache:AuthorizationClient
method that was added for this purpose.Originally I hadn't thought this was necessary since all platform manage token expiration automatically, but as the linked issue highlights there are cases where a non-expired token can become invalid, and in that case it will sit in the cache and continue to be returned on Android and Web. Clients are expected to handle this case when API requests using the token fail (example docs for Android), so we need to provide a method for it.
Fixes flutter/flutter#173924
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3