Skip to content

Commit 06e8e3b

Browse files
AlexZaiatscollinjackson
authored andcommitted
[firebase_auth] getIdToken use actual refresh value instead of checking if object exists (#1334)
* getIdToken use actual refresh value instead of checking if object exists * getIdToken refresh integration test
1 parent d6c93b0 commit 06e8e3b

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

packages/firebase_auth/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.14.0+9
2+
3+
* Fix the behavior of `getIdToken` to use the `refresh` parameter instead of always refreshing.
4+
15
## 0.14.0+8
26

37
* Updated README instructions for contributing for consistency with other Flutterfire plugins.

packages/firebase_auth/example/test/firebase_auth.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void main() {
4040
expect(user.metadata.creationTime.isAfter(DateTime(2018, 1, 1)), isTrue);
4141
expect(user.metadata.creationTime.isBefore(DateTime.now()), isTrue);
4242
final IdTokenResult tokenResult = await user.getIdToken();
43+
final String originalToken = tokenResult.token;
4344
expect(tokenResult.token, isNotNull);
4445
expect(tokenResult.expirationTime.isAfter(DateTime.now()), isTrue);
4546
expect(tokenResult.authTime, isNotNull);
@@ -53,6 +54,10 @@ void main() {
5354
expect(tokenResult.claims['provider_id'], 'anonymous');
5455
expect(tokenResult.claims['firebase']['sign_in_provider'], 'anonymous');
5556
expect(tokenResult.claims['user_id'], user.uid);
57+
// Verify that token will be the same after another getIdToken call with refresh = false option
58+
final IdTokenResult newTokenResultWithoutRefresh =
59+
await user.getIdToken(refresh: false);
60+
expect(originalToken, newTokenResultWithoutRefresh.token);
5661
await auth.signOut();
5762
final FirebaseUser user2 = (await auth.signInAnonymously()).user;
5863
expect(user2.uid, isNot(equals(user.uid)));

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
205205
}
206206
} else if ([@"getIdToken" isEqualToString:call.method]) {
207207
NSDictionary *args = call.arguments;
208-
BOOL refresh = [args objectForKey:@"refresh"];
208+
BOOL refresh = [[args objectForKey:@"refresh"] boolValue];
209209
[[self getAuth:call.arguments].currentUser
210210
getIDTokenResultForcingRefresh:refresh
211211
completion:^(FIRAuthTokenResult *_Nullable tokenResult,

packages/firebase_auth/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
44
like Google, Facebook and Twitter.
55
author: Flutter Team <[email protected]>
66
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth
7-
version: 0.14.0+8
7+
version: 0.14.0+9
88

99
flutter:
1010
plugin:

0 commit comments

Comments
 (0)