Skip to content

Commit 0315ec5

Browse files
Invalidate cache on signOut
1 parent c36dec9 commit 0315ec5

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

packages/google_sign_in/google_sign_in_ios/lib/google_sign_in_ios.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class GoogleSignInIOS extends GoogleSignInPlatform {
118118

119119
@override
120120
Future<void> signOut(SignOutParams params) {
121+
_updateAuthCodeCache(null);
121122
return _api.signOut();
122123
}
123124

packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,108 @@ void main() {
10711071
expect(result, null);
10721072
});
10731073

1074+
test('does not return cached token from authn after signOut', () async {
1075+
const List<String> scopes = <String>['a', 'b'];
1076+
const String accessToken = 'accessToken';
1077+
const String serverAuthCode = 'authCode';
1078+
final UserData userData = UserData(
1079+
displayName: _testUser.displayName,
1080+
email: _testUser.email,
1081+
userId: _testUser.id,
1082+
photoUrl: _testUser.photoUrl,
1083+
idToken: '',
1084+
);
1085+
when(mockApi.signIn(scopes, null)).thenAnswer(
1086+
(_) async => SignInResult(
1087+
success: SignInSuccess(
1088+
user: userData,
1089+
accessToken: accessToken,
1090+
serverAuthCode: serverAuthCode,
1091+
grantedScopes: <String>[],
1092+
),
1093+
),
1094+
);
1095+
when(mockApi.getRefreshedAuthorizationTokens(userData.userId)).thenAnswer(
1096+
(_) async => SignInResult(
1097+
success: SignInSuccess(
1098+
user: userData,
1099+
accessToken: accessToken,
1100+
// serverAuthCode will always be null for getRefreshedAuthorizationTokens.
1101+
grantedScopes: scopes,
1102+
),
1103+
),
1104+
);
1105+
1106+
await googleSignIn.authenticate(
1107+
const AuthenticateParameters(scopeHint: scopes),
1108+
);
1109+
await googleSignIn.signOut(const SignOutParams());
1110+
final ServerAuthorizationTokenData? result = await googleSignIn
1111+
.serverAuthorizationTokensForScopes(
1112+
ServerAuthorizationTokensForScopesParameters(
1113+
request: AuthorizationRequestDetails(
1114+
scopes: scopes,
1115+
userId: userData.userId,
1116+
email: userData.email,
1117+
promptIfUnauthorized: false,
1118+
),
1119+
),
1120+
);
1121+
1122+
expect(result, null);
1123+
});
1124+
1125+
test('does not return cached token from authn after disconnect', () async {
1126+
const List<String> scopes = <String>['a', 'b'];
1127+
const String accessToken = 'accessToken';
1128+
const String serverAuthCode = 'authCode';
1129+
final UserData userData = UserData(
1130+
displayName: _testUser.displayName,
1131+
email: _testUser.email,
1132+
userId: _testUser.id,
1133+
photoUrl: _testUser.photoUrl,
1134+
idToken: '',
1135+
);
1136+
when(mockApi.signIn(scopes, null)).thenAnswer(
1137+
(_) async => SignInResult(
1138+
success: SignInSuccess(
1139+
user: userData,
1140+
accessToken: accessToken,
1141+
serverAuthCode: serverAuthCode,
1142+
grantedScopes: <String>[],
1143+
),
1144+
),
1145+
);
1146+
when(mockApi.getRefreshedAuthorizationTokens(userData.userId)).thenAnswer(
1147+
(_) async => SignInResult(
1148+
success: SignInSuccess(
1149+
user: userData,
1150+
accessToken: accessToken,
1151+
// serverAuthCode will always be null for getRefreshedAuthorizationTokens.
1152+
grantedScopes: scopes,
1153+
),
1154+
),
1155+
);
1156+
1157+
await googleSignIn.authenticate(
1158+
const AuthenticateParameters(scopeHint: scopes),
1159+
);
1160+
await googleSignIn.disconnect(const DisconnectParams());
1161+
final ServerAuthorizationTokenData? result = await googleSignIn
1162+
.serverAuthorizationTokensForScopes(
1163+
ServerAuthorizationTokensForScopesParameters(
1164+
request: AuthorizationRequestDetails(
1165+
scopes: scopes,
1166+
userId: userData.userId,
1167+
email: userData.email,
1168+
promptIfUnauthorized: false,
1169+
),
1170+
),
1171+
);
1172+
1173+
expect(result, null);
1174+
});
1175+
10741176
test(
10751177
'passes returned data to caller when calling addScopes without cache',
10761178
() async {

0 commit comments

Comments
 (0)