Skip to content

Commit 6f979b5

Browse files
[google_sign_in] Add a platform interface method to clear auth tokens (#9929)
Platform interface portion of #9846 Part of flutter/flutter#173924 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent af32689 commit 6f979b5

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 3.1.0
22

3+
* Adds a `clearAuthorizationToken` method to remove an access token from the
4+
cache.
35
* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.
46

57
## 3.0.0

packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ abstract class GoogleSignInPlatform extends PlatformInterface {
9898
ServerAuthorizationTokensForScopesParameters params,
9999
);
100100

101+
/// Clears any token cache for the given access token.
102+
Future<void> clearAuthorizationToken(ClearAuthorizationTokenParams params) {
103+
throw UnimplementedError(
104+
'clearAuthorizationToken() has not been implemented.',
105+
);
106+
}
107+
101108
/// Signs out previously signed in accounts.
102109
Future<void> signOut(SignOutParams params);
103110

@@ -168,6 +175,11 @@ class _PlaceholderImplementation extends GoogleSignInPlatform {
168175
throw UnimplementedError();
169176
}
170177

178+
@override
179+
Future<void> clearAuthorizationToken(ClearAuthorizationTokenParams params) {
180+
throw UnimplementedError();
181+
}
182+
171183
@override
172184
Future<void> signOut(SignOutParams params) {
173185
throw UnimplementedError();

packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,29 @@ class AuthenticationResults {
363363
final AuthenticationTokenData authenticationTokens;
364364
}
365365

366+
/// Parameters for the clearAuthorizationToken method.
367+
@immutable
368+
class ClearAuthorizationTokenParams {
369+
/// Creates new parameters for clearAuthorizationToken with the given
370+
/// [accessToken]
371+
const ClearAuthorizationTokenParams({required this.accessToken});
372+
373+
/// The OAuth2 access token to clear.
374+
final String accessToken;
375+
376+
@override
377+
int get hashCode => accessToken.hashCode;
378+
379+
@override
380+
bool operator ==(Object other) {
381+
if (other.runtimeType != runtimeType) {
382+
return false;
383+
}
384+
return other is ClearAuthorizationTokenParams &&
385+
other.accessToken == accessToken;
386+
}
387+
}
388+
366389
/// Parameters for the signOut method.
367390
@immutable
368391
class SignOutParams {

packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_sign_i
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 3.0.0
7+
version: 3.1.0
88

99
environment:
1010
sdk: ^3.7.0

packages/google_sign_in/google_sign_in_platform_interface/test/google_sign_in_platform_interface_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ void main() {
3737
// this behavior, which could be implemented in the subclass.
3838
expect(ExtendsGoogleSignInPlatform().authenticationEvents, null);
3939
});
40+
41+
test(
42+
'Default implementation of clearAuthorizationToken throws unimplemented error',
43+
() {
44+
final ExtendsGoogleSignInPlatform platform =
45+
ExtendsGoogleSignInPlatform();
46+
47+
expect(
48+
() => platform.clearAuthorizationToken(
49+
const ClearAuthorizationTokenParams(accessToken: 'someToken'),
50+
),
51+
throwsUnimplementedError,
52+
);
53+
},
54+
);
4055
});
4156

4257
group('GoogleSignInUserData', () {

script/tool/bin/flutter_plugin_tools.dart

100644100755
File mode changed.

0 commit comments

Comments
 (0)