From 02b74683d5dddf2ba08d038874ca8fd2de047851 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 16 Jul 2019 21:06:28 -0400 Subject: [PATCH 01/26] Implement getIdTokenResult. --- .../firebaseauth/FirebaseAuthPlugin.java | 22 +++++++++++++++++- .../ios/Classes/FirebaseAuthPlugin.m | 23 +++++++++++++++++++ .../firebase_auth/lib/src/firebase_user.dart | 15 ++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java index 8b0ac80f3a53..af9185454d7f 100755 --- a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java +++ b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java @@ -125,6 +125,7 @@ public void onMethodCall(MethodCall call, Result result) { handleSignOut(call, result, getAuth(call)); break; case "getIdToken": + case "getIdTokenResult": handleGetToken(call, result, getAuth(call)); break; case "reauthenticateWithCredential": @@ -530,6 +531,9 @@ private void handleGetToken(MethodCall call, final Result result, FirebaseAuth f return; } + // Contrary to iOS, android has a single method to handle getIdToken() and getIdTokenResult() + final boolean returnTokenResult = call.method.equals("getIdTokenResult"); + Map arguments = call.arguments(); boolean refresh = arguments.get("refresh"); @@ -540,7 +544,23 @@ private void handleGetToken(MethodCall call, final Result result, FirebaseAuth f public void onComplete(@NonNull Task task) { if (task.isSuccessful() && task.getResult() != null) { String idToken = task.getResult().getToken(); - result.success(idToken); + + if(returnTokenResult) { + Map map = new HashMap<>(); + map.put("token", idToken); + map.put("expirationTimestamp", task.getResult().getExpirationTimestamp()); + map.put("authTimestamp", task.getResult().getAuthTimestamp()); + map.put("issuedAtTimestamp", task.getResult().getIssuedAtTimestamp()); + map.put("claims", task.getResult().getClaims()); + + if(task.getResult().getSignInProvider() != null) { + map.put("signInProvider", task.getResult().getSignInProvider()); + } + + result.success(Collections.unmodifiableMap(map)); + } else { + result.success(idToken); + } } else { reportException(result, task.getException()); } diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index 90dddc04ef31..db35679dfaad 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -203,6 +203,29 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completion:^(NSString *_Nullable token, NSError *_Nullable error) { [self sendResult:result forObject:token error:error]; }]; + } else if ([@"getIdTokenResult" isEqualToString:call.method]) { + NSDictionary *args = call.arguments; + BOOL refresh = [args objectForKey:@"refresh"]; + [[self getAuth:call.arguments].currentUser + getIDTokenResultForcingRefresh:refresh + completion:^(FIRAuthTokenResult * _Nullable tokenResult, NSError * _Nullable error) { + NSMutableDictionary *tokenData = nil; + if(tokenResult != nil) { + tokenData = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"token" : tokenResult.token, + @"expirationTimestamp" : [NSNumber numberWithInt:[tokenResult.expirationDate timeIntervalSince1970]], + @"authTimestamp" : [NSNumber numberWithInt:[tokenResult.authDate timeIntervalSince1970]], + @"issuedAtTimestamp" : [NSNumber numberWithInt:[tokenResult.issuedAtDate timeIntervalSince1970]], + @"claims" : tokenResult.claims, + }]; + + if(tokenResult.signInProvider != nil) { + tokenData[@"signInProvider"] = tokenResult.signInProvider; + } + } + + [self sendResult:result forObject:tokenResult error:error]; + }]; } else if ([@"reauthenticateWithCredential" isEqualToString:call.method]) { [[self getAuth:call.arguments].currentUser reauthenticateAndRetrieveDataWithCredential:[self getCredential:call.arguments] diff --git a/packages/firebase_auth/lib/src/firebase_user.dart b/packages/firebase_auth/lib/src/firebase_user.dart index 60e341648d44..96533a3388f6 100644 --- a/packages/firebase_auth/lib/src/firebase_user.dart +++ b/packages/firebase_auth/lib/src/firebase_user.dart @@ -41,6 +41,21 @@ class FirebaseUser extends UserInfo { }); } + /// Obtains the id token result for the current user, forcing a [refresh] if desired. + /// + /// Useful when authenticating against your own backend. Use our server + /// SDKs or follow the official documentation to securely verify the + /// integrity and validity of this token. + /// + /// Completes with an error if the user is signed out. + Future getIdTokenResult({bool refresh = false}) async { + return await FirebaseAuth.channel + .invokeMethod('getIdTokenResult', { + 'refresh': refresh, + 'app': _app.name, + }); + } + /// Associates a user account from a third-party identity provider with this /// user and returns additional identity provider data. /// From 5de3c8f84ccf3a66b6d134e73ffc23cfa344ae25 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 16 Jul 2019 21:30:07 -0400 Subject: [PATCH 02/26] Implement IdResultToken type. --- .../ios/Classes/FirebaseAuthPlugin.m | 10 ++-- packages/firebase_auth/lib/firebase_auth.dart | 1 + .../firebase_auth/lib/src/firebase_user.dart | 9 ++-- .../lib/src/id_token_result.dart | 50 +++++++++++++++++++ 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 packages/firebase_auth/lib/src/id_token_result.dart diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index db35679dfaad..be95446c18e9 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -211,11 +211,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completion:^(FIRAuthTokenResult * _Nullable tokenResult, NSError * _Nullable error) { NSMutableDictionary *tokenData = nil; if(tokenResult != nil) { + long expirationTimestamp = [tokenResult.expirationDate timeIntervalSince1970]; + long authTimestamp = [tokenResult.authDate timeIntervalSince1970]; + long issuedAtTimestamp = [tokenResult.issuedAtDate timeIntervalSince1970]; + tokenData = [[NSMutableDictionary alloc] initWithDictionary:@{ @"token" : tokenResult.token, - @"expirationTimestamp" : [NSNumber numberWithInt:[tokenResult.expirationDate timeIntervalSince1970]], - @"authTimestamp" : [NSNumber numberWithInt:[tokenResult.authDate timeIntervalSince1970]], - @"issuedAtTimestamp" : [NSNumber numberWithInt:[tokenResult.issuedAtDate timeIntervalSince1970]], + @"expirationTimestamp" : [NSNumber numberWithInt:expirationTimestamp], + @"authTimestamp" : [NSNumber numberWithInt:authTimestamp], + @"issuedAtTimestamp" : [NSNumber numberWithInt:issuedAtTimestamp], @"claims" : tokenResult.claims, }]; diff --git a/packages/firebase_auth/lib/firebase_auth.dart b/packages/firebase_auth/lib/firebase_auth.dart index 1f31ead02dc0..927b99055f9b 100755 --- a/packages/firebase_auth/lib/firebase_auth.dart +++ b/packages/firebase_auth/lib/firebase_auth.dart @@ -20,6 +20,7 @@ part 'src/auth_credential.dart'; part 'src/auth_exception.dart'; part 'src/firebase_auth.dart'; part 'src/firebase_user.dart'; +part 'src/id_token_result.dart'; part 'src/user_info.dart'; part 'src/user_metadata.dart'; part 'src/user_update_info.dart'; diff --git a/packages/firebase_auth/lib/src/firebase_user.dart b/packages/firebase_auth/lib/src/firebase_user.dart index 96533a3388f6..7ee313196bd8 100644 --- a/packages/firebase_auth/lib/src/firebase_user.dart +++ b/packages/firebase_auth/lib/src/firebase_user.dart @@ -48,12 +48,15 @@ class FirebaseUser extends UserInfo { /// integrity and validity of this token. /// /// Completes with an error if the user is signed out. - Future getIdTokenResult({bool refresh = false}) async { - return await FirebaseAuth.channel - .invokeMethod('getIdTokenResult', { + Future getIdTokenResult({bool refresh = false}) async { + final Map data = await FirebaseAuth.channel + .invokeMapMethod('getIdTokenResult', { 'refresh': refresh, 'app': _app.name, }); + + final IdTokenResult idTokenResult = IdTokenResult._(data, _app); + return idTokenResult; } /// Associates a user account from a third-party identity provider with this diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart new file mode 100644 index 000000000000..ea61984ec333 --- /dev/null +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -0,0 +1,50 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +part of firebase_auth; + +/// Represents ID token result obtained from FirebaseUser +/// It contains the ID token JWT string +/// and other helper properties for getting different data associated with the +/// token as well as all the decoded payload claims. +/// +/// Note that these claims are not to be trusted as they are parsed client side. +/// Only server side verification can guarantee the integrity of the token +/// claims. +class IdTokenResult { + IdTokenResult._(this._data, this._app); + + final FirebaseApp _app; + + final Map _data; + + /// The Firebase Auth ID token JWT string. + String get token => _data['token']; + + /// The ID token expiration time formatted. + DateTime get expirationDate => + DateTime.fromMillisecondsSinceEpoch(_data['expirationTimestamp'] * 1000); + + /// The authentication time. This is the time the + /// user authenticated (signed in) and not the time the token was refreshed. + DateTime get authDate => + DateTime.fromMillisecondsSinceEpoch(_data['authTimestamp'] * 1000); + + /// The ID token issued at time formatted. + DateTime get issuedAtDate => + DateTime.fromMillisecondsSinceEpoch(_data['issuedAtTimestamp'] * 1000); + + /// The sign-in provider through which the ID token was obtained (anonymous, + /// custom, phone, password, etc). Note, this does not map to provider IDs. + String get signInProvider => _data['signInProvider']; + + /// The entire payload claims of the ID token including the standard reserved + /// claims as well as the custom claims. + Map get claims => _data['claims']; + + @override + String toString() { + return '$runtimeType($_data)'; + } +} From b2c98d9390c86f1f137554e93a7fdd0e392cc25e Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 16 Jul 2019 22:17:26 -0400 Subject: [PATCH 03/26] Fix typo. --- packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index be95446c18e9..5c90f29bdd01 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -228,7 +228,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } } - [self sendResult:result forObject:tokenResult error:error]; + [self sendResult:result forObject:tokenData error:error]; }]; } else if ([@"reauthenticateWithCredential" isEqualToString:call.method]) { [[self getAuth:call.arguments].currentUser From af5302e03cd7efd668877006779b717be5e7ec96 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 16 Jul 2019 22:23:00 -0400 Subject: [PATCH 04/26] Fix claims type. --- packages/firebase_auth/lib/src/id_token_result.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index ea61984ec333..5ca57a8ce17c 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -41,7 +41,7 @@ class IdTokenResult { /// The entire payload claims of the ID token including the standard reserved /// claims as well as the custom claims. - Map get claims => _data['claims']; + Map get claims => Map.from(_data['claims']); @override String toString() { From 8e8a315f0987866f33e08e86c9a932a8c47370f1 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 16 Jul 2019 22:31:32 -0400 Subject: [PATCH 05/26] Fix claims type (2). --- packages/firebase_auth/lib/src/id_token_result.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index 5ca57a8ce17c..ac57f4958b4e 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -41,7 +41,7 @@ class IdTokenResult { /// The entire payload claims of the ID token including the standard reserved /// claims as well as the custom claims. - Map get claims => Map.from(_data['claims']); + Map get claims => _data['claims']; @override String toString() { From 09f6efa399bf3c51c67a56f6d08a8f05a4e8a176 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 16 Jul 2019 22:38:40 -0400 Subject: [PATCH 06/26] Fix claims type (3). --- packages/firebase_auth/lib/src/id_token_result.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index ac57f4958b4e..937ed53c665e 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -41,7 +41,8 @@ class IdTokenResult { /// The entire payload claims of the ID token including the standard reserved /// claims as well as the custom claims. - Map get claims => _data['claims']; + Map get claims => + Map.from(_data['claims']); @override String toString() { From 52620ba27a5c4ef23a618f7b28c308c4f5ef0b0c Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 16 Jul 2019 22:45:52 -0400 Subject: [PATCH 07/26] =?UTF-8?q?Revert=20=E2=80=9CFix=20claims=20type=20(?= =?UTF-8?q?3)=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/firebase_auth/lib/src/id_token_result.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index 937ed53c665e..ac57f4958b4e 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -41,8 +41,7 @@ class IdTokenResult { /// The entire payload claims of the ID token including the standard reserved /// claims as well as the custom claims. - Map get claims => - Map.from(_data['claims']); + Map get claims => _data['claims']; @override String toString() { From d7812c0cd416403e0bcb751c26b2bfef21320620 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Fri, 26 Jul 2019 11:54:21 -0400 Subject: [PATCH 08/26] Implement changes for renaming, add tests and changelog. --- packages/firebase_auth/CHANGELOG.md | 6 +++ .../firebaseauth/FirebaseAuthPlugin.java | 34 ++++++--------- .../ios/Classes/FirebaseAuthPlugin.m | 6 --- .../firebase_auth/lib/src/firebase_user.dart | 22 ++-------- .../lib/src/id_token_result.dart | 3 +- .../test/firebase_auth_test.dart | 43 +++++++++++++++++-- 6 files changed, 63 insertions(+), 51 deletions(-) diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index 8a9adcfb9b3e..b1fc835b6bd0 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.12.0 + + * Added new `IdTokenResult` class. + * **Breaking Change**. `getIdToken()` method now returns `IdTokenResult` instead of just the `String token`. + Retrieve the `String token` using the `token` property of `IdTokenResult`. + ## 0.11.1+10 * On Android, `providerData` now includes `UserInfo` for the phone authentication provider. diff --git a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java index af9185454d7f..d21beefd4075 100755 --- a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java +++ b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java @@ -125,7 +125,6 @@ public void onMethodCall(MethodCall call, Result result) { handleSignOut(call, result, getAuth(call)); break; case "getIdToken": - case "getIdTokenResult": handleGetToken(call, result, getAuth(call)); break; case "reauthenticateWithCredential": @@ -531,11 +530,8 @@ private void handleGetToken(MethodCall call, final Result result, FirebaseAuth f return; } - // Contrary to iOS, android has a single method to handle getIdToken() and getIdTokenResult() - final boolean returnTokenResult = call.method.equals("getIdTokenResult"); - Map arguments = call.arguments(); - boolean refresh = arguments.get("refresh"); + final boolean refresh = arguments.get("refresh"); currentUser .getIdToken(refresh) @@ -543,24 +539,18 @@ private void handleGetToken(MethodCall call, final Result result, FirebaseAuth f new OnCompleteListener() { public void onComplete(@NonNull Task task) { if (task.isSuccessful() && task.getResult() != null) { - String idToken = task.getResult().getToken(); - - if(returnTokenResult) { - Map map = new HashMap<>(); - map.put("token", idToken); - map.put("expirationTimestamp", task.getResult().getExpirationTimestamp()); - map.put("authTimestamp", task.getResult().getAuthTimestamp()); - map.put("issuedAtTimestamp", task.getResult().getIssuedAtTimestamp()); - map.put("claims", task.getResult().getClaims()); - - if(task.getResult().getSignInProvider() != null) { - map.put("signInProvider", task.getResult().getSignInProvider()); - } - - result.success(Collections.unmodifiableMap(map)); - } else { - result.success(idToken); + final Map map = new HashMap<>(); + map.put("token", task.getResult().getToken()); + map.put("expirationTimestamp", task.getResult().getExpirationTimestamp()); + map.put("authTimestamp", task.getResult().getAuthTimestamp()); + map.put("issuedAtTimestamp", task.getResult().getIssuedAtTimestamp()); + map.put("claims", task.getResult().getClaims()); + + if(task.getResult().getSignInProvider() != null) { + map.put("signInProvider", task.getResult().getSignInProvider()); } + + result.success(Collections.unmodifiableMap(map)); } else { reportException(result, task.getException()); } diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index 5c90f29bdd01..7073d0518830 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -198,12 +198,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self sendResult:result forObject:nil error:nil]; } } else if ([@"getIdToken" isEqualToString:call.method]) { - [[self getAuth:call.arguments].currentUser - getIDTokenForcingRefresh:YES - completion:^(NSString *_Nullable token, NSError *_Nullable error) { - [self sendResult:result forObject:token error:error]; - }]; - } else if ([@"getIdTokenResult" isEqualToString:call.method]) { NSDictionary *args = call.arguments; BOOL refresh = [args objectForKey:@"refresh"]; [[self getAuth:call.arguments].currentUser diff --git a/packages/firebase_auth/lib/src/firebase_user.dart b/packages/firebase_auth/lib/src/firebase_user.dart index 7ee313196bd8..b883d02473e0 100644 --- a/packages/firebase_auth/lib/src/firebase_user.dart +++ b/packages/firebase_auth/lib/src/firebase_user.dart @@ -26,21 +26,6 @@ class FirebaseUser extends UserInfo { /// Returns true if the user's email is verified. bool get isEmailVerified => _data['isEmailVerified']; - /// Obtains the id token for the current user, forcing a [refresh] if desired. - /// - /// Useful when authenticating against your own backend. Use our server - /// SDKs or follow the official documentation to securely verify the - /// integrity and validity of this token. - /// - /// Completes with an error if the user is signed out. - Future getIdToken({bool refresh = false}) async { - return await FirebaseAuth.channel - .invokeMethod('getIdToken', { - 'refresh': refresh, - 'app': _app.name, - }); - } - /// Obtains the id token result for the current user, forcing a [refresh] if desired. /// /// Useful when authenticating against your own backend. Use our server @@ -48,15 +33,14 @@ class FirebaseUser extends UserInfo { /// integrity and validity of this token. /// /// Completes with an error if the user is signed out. - Future getIdTokenResult({bool refresh = false}) async { + Future getIdToken({bool refresh = false}) async { final Map data = await FirebaseAuth.channel - .invokeMapMethod('getIdTokenResult', { + .invokeMapMethod('getIdToken', { 'refresh': refresh, 'app': _app.name, }); - final IdTokenResult idTokenResult = IdTokenResult._(data, _app); - return idTokenResult; + return IdTokenResult(data, _app); } /// Associates a user account from a third-party identity provider with this diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index ac57f4958b4e..032dd9ddf7e4 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -13,7 +13,8 @@ part of firebase_auth; /// Only server side verification can guarantee the integrity of the token /// claims. class IdTokenResult { - IdTokenResult._(this._data, this._app); + @visibleForTesting + IdTokenResult(this._data, this._app); final FirebaseApp _app; diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 928cb9916854..b0271c7b3607 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -25,6 +25,13 @@ const String kMockPhoneNumber = '5555555555'; const String kMockVerificationId = '12345'; const String kMockSmsCode = '123456'; const String kMockLanguage = 'en'; +const String kMockIdTokenResultSignInProvider = 'password'; +const Map kMockIdTokenResultClaims = { + 'claim1': 'value1', +}; +const int kMockIdTokenResultExpirationTimestamp = 123456; +const int kMockIdTokenResultAuthTimestamp = 1234567; +const int kMockIdTokenResultIssuedAtTimestamp = 12345678; void main() { group('$FirebaseAuth', () { @@ -41,7 +48,7 @@ void main() { log.add(call); switch (call.method) { case "getIdToken": - return kMockIdToken; + return mockIdTokenResult(); break; case "isSignInWithEmailLink": return true; @@ -93,11 +100,32 @@ void main() { ); }); + void verifyIdTokenResult(IdTokenResult idTokenResult) { + expect(idTokenResult.token, equals(kMockIdToken)); + expect( + idTokenResult.expirationDate, + equals(DateTime.fromMillisecondsSinceEpoch( + kMockIdTokenResultExpirationTimestamp * 1000))); + expect( + idTokenResult.authDate, + equals(DateTime.fromMillisecondsSinceEpoch( + kMockIdTokenResultAuthTimestamp * 1000))); + expect( + idTokenResult.issuedAtDate, + equals(DateTime.fromMillisecondsSinceEpoch( + kMockIdTokenResultIssuedAtTimestamp * 1000))); + expect(idTokenResult.signInProvider, + equals(kMockIdTokenResultSignInProvider)); + expect(idTokenResult.claims, equals(kMockIdTokenResultClaims)); + } + test('signInAnonymously', () async { final FirebaseUser user = await auth.signInAnonymously(); verifyUser(user); - expect(await user.getIdToken(), equals(kMockIdToken)); - expect(await user.getIdToken(refresh: true), equals(kMockIdToken)); + + verifyIdTokenResult(await user.getIdToken()); + verifyIdTokenResult(await user.getIdToken(refresh: true)); + expect( log, [ @@ -1231,6 +1259,15 @@ Map mockFirebaseUser( ], }; +Map mockIdTokenResult() => { + 'token': kMockIdToken, + 'expirationTimestamp': kMockIdTokenResultExpirationTimestamp, + 'authTimestamp': kMockIdTokenResultAuthTimestamp, + 'issuedAtTimestamp': kMockIdTokenResultIssuedAtTimestamp, + 'signInProvider': kMockIdTokenResultSignInProvider, + 'claims': kMockIdTokenResultClaims, + }; + /// Queue whose remove operation is asynchronous, awaiting a corresponding add. class AsyncQueue { Map> _completers = >{}; From b33c4241365b334086802927770c67bfea49d8a5 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Fri, 26 Jul 2019 11:58:06 -0400 Subject: [PATCH 09/26] Reformat. --- .../io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java index d21beefd4075..adb6611f8135 100755 --- a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java +++ b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java @@ -546,7 +546,7 @@ public void onComplete(@NonNull Task task) { map.put("issuedAtTimestamp", task.getResult().getIssuedAtTimestamp()); map.put("claims", task.getResult().getClaims()); - if(task.getResult().getSignInProvider() != null) { + if (task.getResult().getSignInProvider() != null) { map.put("signInProvider", task.getResult().getSignInProvider()); } From a8ba0fb188b6bd165f3d50bd0b57490d8a5d85e2 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 15:16:45 -0700 Subject: [PATCH 10/26] Update CHANGELOG.md --- packages/firebase_auth/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index b1fc835b6bd0..c3771de34013 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md @@ -1,8 +1,8 @@ ## 0.12.0 * Added new `IdTokenResult` class. - * **Breaking Change**. `getIdToken()` method now returns `IdTokenResult` instead of just the `String token`. - Retrieve the `String token` using the `token` property of `IdTokenResult`. + * **Breaking Change**. `getIdToken()` method now returns `IdTokenResult` instead of just the token `String`. + Retrieve the token `String` using the `token` property of `IdTokenResult`. ## 0.11.1+10 From 8928753ea350df0a5c66a8a4a098e0fd88cef407 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 15:22:37 -0700 Subject: [PATCH 11/26] Update id_token_result.dart Update comments --- .../firebase_auth/lib/src/id_token_result.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index 032dd9ddf7e4..af71bb0b2d83 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -4,10 +4,9 @@ part of firebase_auth; -/// Represents ID token result obtained from FirebaseUser -/// It contains the ID token JWT string -/// and other helper properties for getting different data associated with the -/// token as well as all the decoded payload claims. +/// Represents ID token result obtained from [FirebaseUser], containing the +/// ID token JWT string and other helper properties for getting different +/// data associated with the token as well as all the decoded payload claims. /// /// Note that these claims are not to be trusted as they are parsed client side. /// Only server side verification can guarantee the integrity of the token @@ -23,16 +22,17 @@ class IdTokenResult { /// The Firebase Auth ID token JWT string. String get token => _data['token']; - /// The ID token expiration time formatted. + /// The time when the ID token expires. DateTime get expirationDate => DateTime.fromMillisecondsSinceEpoch(_data['expirationTimestamp'] * 1000); - /// The authentication time. This is the time the - /// user authenticated (signed in) and not the time the token was refreshed. + /// The time the user authenticated (signed in). + /// + /// Note that this is not the time the token was refreshed. DateTime get authDate => DateTime.fromMillisecondsSinceEpoch(_data['authTimestamp'] * 1000); - /// The ID token issued at time formatted. + /// The time when ID token was issued. DateTime get issuedAtDate => DateTime.fromMillisecondsSinceEpoch(_data['issuedAtTimestamp'] * 1000); From dd4fa4848edd51527e528c22d0c2917c98839908 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 15:30:03 -0700 Subject: [PATCH 12/26] Reformat --- .../ios/Classes/FirebaseAuthPlugin.m | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index 7073d0518830..64b918394faf 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -201,29 +201,33 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSDictionary *args = call.arguments; BOOL refresh = [args objectForKey:@"refresh"]; [[self getAuth:call.arguments].currentUser - getIDTokenResultForcingRefresh:refresh - completion:^(FIRAuthTokenResult * _Nullable tokenResult, NSError * _Nullable error) { - NSMutableDictionary *tokenData = nil; - if(tokenResult != nil) { - long expirationTimestamp = [tokenResult.expirationDate timeIntervalSince1970]; - long authTimestamp = [tokenResult.authDate timeIntervalSince1970]; - long issuedAtTimestamp = [tokenResult.issuedAtDate timeIntervalSince1970]; - - tokenData = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"token" : tokenResult.token, - @"expirationTimestamp" : [NSNumber numberWithInt:expirationTimestamp], - @"authTimestamp" : [NSNumber numberWithInt:authTimestamp], - @"issuedAtTimestamp" : [NSNumber numberWithInt:issuedAtTimestamp], - @"claims" : tokenResult.claims, - }]; - - if(tokenResult.signInProvider != nil) { - tokenData[@"signInProvider"] = tokenResult.signInProvider; - } - } - - [self sendResult:result forObject:tokenData error:error]; - }]; + getIDTokenResultForcingRefresh:refresh + completion:^(FIRAuthTokenResult *_Nullable tokenResult, + NSError *_Nullable error) { + NSMutableDictionary *tokenData = nil; + if (tokenResult != nil) { + long expirationTimestamp = + [tokenResult.expirationDate timeIntervalSince1970]; + long authTimestamp = [tokenResult.authDate timeIntervalSince1970]; + long issuedAtTimestamp = + [tokenResult.issuedAtDate timeIntervalSince1970]; + + tokenData = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"token" : tokenResult.token, + @"expirationTimestamp" : + [NSNumber numberWithInt:expirationTimestamp], + @"authTimestamp" : [NSNumber numberWithInt:authTimestamp], + @"issuedAtTimestamp" : [NSNumber numberWithInt:issuedAtTimestamp], + @"claims" : tokenResult.claims, + }]; + + if (tokenResult.signInProvider != nil) { + tokenData[@"signInProvider"] = tokenResult.signInProvider; + } + } + + [self sendResult:result forObject:tokenData error:error]; + }]; } else if ([@"reauthenticateWithCredential" isEqualToString:call.method]) { [[self getAuth:call.arguments].currentUser reauthenticateAndRetrieveDataWithCredential:[self getCredential:call.arguments] From 423078e431c53021d303d050036e6ab080b74346 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 15:34:34 -0700 Subject: [PATCH 13/26] Update *Date methods to Time instead --- packages/firebase_auth/lib/src/id_token_result.dart | 6 +++--- packages/firebase_auth/test/firebase_auth_test.dart | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index af71bb0b2d83..d58ac673eec3 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -23,17 +23,17 @@ class IdTokenResult { String get token => _data['token']; /// The time when the ID token expires. - DateTime get expirationDate => + DateTime get expirationTime => DateTime.fromMillisecondsSinceEpoch(_data['expirationTimestamp'] * 1000); /// The time the user authenticated (signed in). /// /// Note that this is not the time the token was refreshed. - DateTime get authDate => + DateTime get authTime => DateTime.fromMillisecondsSinceEpoch(_data['authTimestamp'] * 1000); /// The time when ID token was issued. - DateTime get issuedAtDate => + DateTime get issuedAtTime => DateTime.fromMillisecondsSinceEpoch(_data['issuedAtTimestamp'] * 1000); /// The sign-in provider through which the ID token was obtained (anonymous, diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index b0271c7b3607..47959dbdc9b0 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -103,15 +103,15 @@ void main() { void verifyIdTokenResult(IdTokenResult idTokenResult) { expect(idTokenResult.token, equals(kMockIdToken)); expect( - idTokenResult.expirationDate, + idTokenResult.expirationTime, equals(DateTime.fromMillisecondsSinceEpoch( kMockIdTokenResultExpirationTimestamp * 1000))); expect( - idTokenResult.authDate, + idTokenResult.authTime, equals(DateTime.fromMillisecondsSinceEpoch( kMockIdTokenResultAuthTimestamp * 1000))); expect( - idTokenResult.issuedAtDate, + idTokenResult.issuedAtTime, equals(DateTime.fromMillisecondsSinceEpoch( kMockIdTokenResultIssuedAtTimestamp * 1000))); expect(idTokenResult.signInProvider, From 883099ee72bdcae599425fec9349188058d6c670 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 15:46:27 -0700 Subject: [PATCH 14/26] Add integration testing --- packages/firebase_auth/example/test/firebase_auth.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index 2c4f4c8ede32..b8fe0f92777f 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -19,6 +19,15 @@ void main() { final FirebaseUser user = await auth.signInAnonymously(); expect(user.uid, isNotNull); expect(user.isAnonymous, isTrue); + final IdTokenResult result = await user.getIdToken(); + expect(result.token, isNotNull); + expect(result.expirationTime.isAfter(DateTime.now()), isTrue); + expect(result.authTime, isNotNull); + expect(result.issuedAtTime, isNotNull); + expect(result.signInProvider, 'anonymous'); + expect(result.claims['provider_id'], 'anonymous'); + expect(result.claims['firebase']['sign_in_provider'], 'anonymous'); + expect(result.claims['user_id'], user.uid); }); test('isSignInWithEmailLink', () async { From beb1cb63ba467f89ce9edbb522dabe9dc2ae2cb7 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 15:49:24 -0700 Subject: [PATCH 15/26] Update CHANGELOG.md --- packages/firebase_auth/CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index 7ca7d1f91ef4..ac9217191415 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md @@ -1,8 +1,9 @@ ## 0.12.0 - * Added new `IdTokenResult` class. - * **Breaking Change**. `getIdToken()` method now returns `IdTokenResult` instead of just the token `String`. - Retrieve the token `String` using the `token` property of `IdTokenResult`. +* Added new `IdTokenResult` class. +* **Breaking Change**. `getIdToken()` method now returns `IdTokenResult` instead of a token `String`. + Use the `token` property of `IdTokenResult` to retrieve the token `String`. +* Added integration testing for `getIdToken()`. ## 0.11.1+12 From 6ddd601df57d65eb118b2bc2a522f410e63a781b Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 16:53:49 -0700 Subject: [PATCH 16/26] Reformat --- packages/firebase_auth/lib/src/id_token_result.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_auth/lib/src/id_token_result.dart b/packages/firebase_auth/lib/src/id_token_result.dart index d58ac673eec3..c53e9ae5bb4d 100644 --- a/packages/firebase_auth/lib/src/id_token_result.dart +++ b/packages/firebase_auth/lib/src/id_token_result.dart @@ -27,7 +27,7 @@ class IdTokenResult { DateTime.fromMillisecondsSinceEpoch(_data['expirationTimestamp'] * 1000); /// The time the user authenticated (signed in). - /// + /// /// Note that this is not the time the token was refreshed. DateTime get authTime => DateTime.fromMillisecondsSinceEpoch(_data['authTimestamp'] * 1000); From 5c4cdc63c8eeb859626a504229a5a4a8759df549 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 18:49:17 -0700 Subject: [PATCH 17/26] Fix integration test --- packages/firebase_auth/example/test/firebase_auth.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index b8fe0f92777f..bdde688c8a8a 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; +import 'dart:io'; import 'package:flutter_driver/driver_extension.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:firebase_auth/firebase_auth.dart'; @@ -24,7 +25,11 @@ void main() { expect(result.expirationTime.isAfter(DateTime.now()), isTrue); expect(result.authTime, isNotNull); expect(result.issuedAtTime, isNotNull); - expect(result.signInProvider, 'anonymous'); + // TODO(jackson): Remove this `if` check once iOS is fixed + // https://github.com/firebase/firebase-ios-sdk/issues/3445 + if (Platform.isAndroid) { + expect(result.signInProvider, 'anonymous'); + } expect(result.claims['provider_id'], 'anonymous'); expect(result.claims['firebase']['sign_in_provider'], 'anonymous'); expect(result.claims['user_id'], user.uid); From ea397c85dc01b905ee3280e8c1af854cba40e7af Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 19:34:23 -0700 Subject: [PATCH 18/26] merge damage --- .../test/firebase_auth_test.dart | 53 ++++--------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 7fc4989e1707..3a97257e7b82 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -38,6 +38,15 @@ const Map kMockAdditionalUserInfo = { 'providerId': 'testProvider', 'profile': {'foo': 'bar'}, }; +const Map kMockIdTokenResult = const { + 'token': kMockIdToken, + 'expirationTimestamp': kMockIdTokenResultExpirationTimestamp, + 'authTimestamp': kMockIdTokenResultAuthTimestamp, + 'issuedAtTimestamp': kMockIdTokenResultIssuedAtTimestamp, + 'signInProvider': kMockIdTokenResultSignInProvider, + 'claims': kMockIdTokenResultClaims, + }; + const Map kMockUser = { 'isAnonymous': true, 'isEmailVerified': false, @@ -67,7 +76,7 @@ void main() { log.add(call); switch (call.method) { case "getIdToken": - return mockIdTokenResult(); + return kMockIdTokenResult; break; case "isSignInWithEmailLink": return true; @@ -123,7 +132,6 @@ void main() { expect(additionalUserInfo.profile, kMockAdditionalUserInfo['profile']); } -<<<<<<< HEAD void verifyIdTokenResult(IdTokenResult idTokenResult) { expect(idTokenResult.token, equals(kMockIdToken)); expect( @@ -143,19 +151,10 @@ void main() { expect(idTokenResult.claims, equals(kMockIdTokenResultClaims)); } - test('signInAnonymously', () async { - final FirebaseUser user = await auth.signInAnonymously(); - verifyUser(user); - - verifyIdTokenResult(await user.getIdToken()); - verifyIdTokenResult(await user.getIdToken(refresh: true)); - -======= test('getIdToken', () async { final FirebaseUser user = await auth.currentUser(); expect(await user.getIdToken(), equals(kMockIdToken)); expect(await user.getIdToken(refresh: true), equals(kMockIdToken)); ->>>>>>> origin/master expect( log, [ @@ -1293,38 +1292,6 @@ void main() { }); } -<<<<<<< HEAD -Map mockFirebaseUser( - {String providerId = kMockProviderId, - String uid = kMockUid, - String displayName = kMockDisplayName, - String photoUrl = kMockPhotoUrl, - String email = kMockEmail}) => - { - 'isAnonymous': true, - 'isEmailVerified': false, - 'providerData': >[ - { - 'providerId': providerId, - 'uid': uid, - 'displayName': displayName, - 'photoUrl': photoUrl, - 'email': email, - }, - ], - }; - -Map mockIdTokenResult() => { - 'token': kMockIdToken, - 'expirationTimestamp': kMockIdTokenResultExpirationTimestamp, - 'authTimestamp': kMockIdTokenResultAuthTimestamp, - 'issuedAtTimestamp': kMockIdTokenResultIssuedAtTimestamp, - 'signInProvider': kMockIdTokenResultSignInProvider, - 'claims': kMockIdTokenResultClaims, - }; - -======= ->>>>>>> origin/master /// Queue whose remove operation is asynchronous, awaiting a corresponding add. class AsyncQueue { Map> _completers = >{}; From 0b537cc90a9353de3c2c1ffb7d5e2374bdc131f3 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 19:54:47 -0700 Subject: [PATCH 19/26] fix test failure --- .../test/firebase_auth_test.dart | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 3a97257e7b82..7e01b185eb1d 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -132,29 +132,28 @@ void main() { expect(additionalUserInfo.profile, kMockAdditionalUserInfo['profile']); } - void verifyIdTokenResult(IdTokenResult idTokenResult) { - expect(idTokenResult.token, equals(kMockIdToken)); - expect( - idTokenResult.expirationTime, - equals(DateTime.fromMillisecondsSinceEpoch( - kMockIdTokenResultExpirationTimestamp * 1000))); - expect( - idTokenResult.authTime, - equals(DateTime.fromMillisecondsSinceEpoch( - kMockIdTokenResultAuthTimestamp * 1000))); - expect( - idTokenResult.issuedAtTime, - equals(DateTime.fromMillisecondsSinceEpoch( - kMockIdTokenResultIssuedAtTimestamp * 1000))); - expect(idTokenResult.signInProvider, - equals(kMockIdTokenResultSignInProvider)); - expect(idTokenResult.claims, equals(kMockIdTokenResultClaims)); - } - test('getIdToken', () async { + void verifyIdTokenResult(IdTokenResult idTokenResult) { + expect(idTokenResult.token, equals(kMockIdToken)); + expect( + idTokenResult.expirationTime, + equals(DateTime.fromMillisecondsSinceEpoch( + kMockIdTokenResultExpirationTimestamp * 1000))); + expect( + idTokenResult.authTime, + equals(DateTime.fromMillisecondsSinceEpoch( + kMockIdTokenResultAuthTimestamp * 1000))); + expect( + idTokenResult.issuedAtTime, + equals(DateTime.fromMillisecondsSinceEpoch( + kMockIdTokenResultIssuedAtTimestamp * 1000))); + expect(idTokenResult.signInProvider, + equals(kMockIdTokenResultSignInProvider)); + expect(idTokenResult.claims, equals(kMockIdTokenResultClaims)); + } final FirebaseUser user = await auth.currentUser(); - expect(await user.getIdToken(), equals(kMockIdToken)); - expect(await user.getIdToken(refresh: true), equals(kMockIdToken)); + verifyIdTokenResult(await user.getIdToken()); + verifyIdTokenResult(await user.getIdToken(refresh: true)); expect( log, [ From 3c4946a29671bb6e58c7279c11f7aa82a15879f0 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 19:56:30 -0700 Subject: [PATCH 20/26] Fix build --- .../example/test/firebase_auth.dart | 18 +++++++++--------- .../firebase_auth/test/firebase_auth_test.dart | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index 3093b0617953..c407396ad3a6 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -26,19 +26,19 @@ void main() { expect(additionalUserInfo.providerId, isNull); expect(user.uid, isNotNull); expect(user.isAnonymous, isTrue); - final IdTokenResult result = await user.getIdToken(); - expect(result.token, isNotNull); - expect(result.expirationTime.isAfter(DateTime.now()), isTrue); - expect(result.authTime, isNotNull); - expect(result.issuedAtTime, isNotNull); + final IdTokenResult tokenResult = await user.getIdToken(); + expect(tokenResult.token, isNotNull); + expect(tokenResult.expirationTime.isAfter(DateTime.now()), isTrue); + expect(tokenResult.authTime, isNotNull); + expect(tokenResult.issuedAtTime, isNotNull); // TODO(jackson): Remove this `if` check once iOS is fixed // https://github.com/firebase/firebase-ios-sdk/issues/3445 if (Platform.isAndroid) { - expect(result.signInProvider, 'anonymous'); + expect(tokenResult.signInProvider, 'anonymous'); } - expect(result.claims['provider_id'], 'anonymous'); - expect(result.claims['firebase']['sign_in_provider'], 'anonymous'); - expect(result.claims['user_id'], user.uid); + expect(tokenResult.claims['provider_id'], 'anonymous'); + expect(tokenResult.claims['firebase']['sign_in_provider'], 'anonymous'); + expect(tokenResult.claims['user_id'], user.uid); }); test('isSignInWithEmailLink', () async { diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 7e01b185eb1d..1f9906ac234f 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -38,7 +38,7 @@ const Map kMockAdditionalUserInfo = { 'providerId': 'testProvider', 'profile': {'foo': 'bar'}, }; -const Map kMockIdTokenResult = const { +const Map kMockIdTokenResult = { 'token': kMockIdToken, 'expirationTimestamp': kMockIdTokenResultExpirationTimestamp, 'authTimestamp': kMockIdTokenResultAuthTimestamp, From 5dcb1872749fbe48bc264069213ee9d6d38b9269 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sat, 27 Jul 2019 20:06:35 -0700 Subject: [PATCH 21/26] Reformat --- .../firebase_auth/test/firebase_auth_test.dart | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 1f9906ac234f..8051899b520c 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -39,13 +39,13 @@ const Map kMockAdditionalUserInfo = { 'profile': {'foo': 'bar'}, }; const Map kMockIdTokenResult = { - 'token': kMockIdToken, - 'expirationTimestamp': kMockIdTokenResultExpirationTimestamp, - 'authTimestamp': kMockIdTokenResultAuthTimestamp, - 'issuedAtTimestamp': kMockIdTokenResultIssuedAtTimestamp, - 'signInProvider': kMockIdTokenResultSignInProvider, - 'claims': kMockIdTokenResultClaims, - }; + 'token': kMockIdToken, + 'expirationTimestamp': kMockIdTokenResultExpirationTimestamp, + 'authTimestamp': kMockIdTokenResultAuthTimestamp, + 'issuedAtTimestamp': kMockIdTokenResultIssuedAtTimestamp, + 'signInProvider': kMockIdTokenResultSignInProvider, + 'claims': kMockIdTokenResultClaims, +}; const Map kMockUser = { 'isAnonymous': true, @@ -151,6 +151,7 @@ void main() { equals(kMockIdTokenResultSignInProvider)); expect(idTokenResult.claims, equals(kMockIdTokenResultClaims)); } + final FirebaseUser user = await auth.currentUser(); verifyIdTokenResult(await user.getIdToken()); verifyIdTokenResult(await user.getIdToken(refresh: true)); From 5386ee74d82f255652183ea332fa087bed7bde9b Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 28 Jul 2019 13:41:39 -0700 Subject: [PATCH 22/26] Remove unused import --- packages/firebase_auth/example/test/firebase_auth.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index 1f61eb129067..2118332bc5b7 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; -import 'dart:io'; import 'package:flutter_driver/driver_extension.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:firebase_auth/firebase_auth.dart'; From 299f2570220e0bf72f08b586a589fa113e1619c0 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 28 Jul 2019 13:44:47 -0700 Subject: [PATCH 23/26] Update version to 0.13.0 to reflect breaking change --- packages/firebase_auth/CHANGELOG.md | 2 +- packages/firebase_auth/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index e88c80d28a38..a97251689694 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.12.1 +## 0.13.0 * Added new `IdTokenResult` class. * **Breaking Change**. `getIdToken()` method now returns `IdTokenResult` instead of a token `String`. diff --git a/packages/firebase_auth/pubspec.yaml b/packages/firebase_auth/pubspec.yaml index f3fd0520aff1..deabd4712be2 100755 --- a/packages/firebase_auth/pubspec.yaml +++ b/packages/firebase_auth/pubspec.yaml @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS like Google, Facebook and Twitter. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth -version: "0.12.0+1" +version: 0.13.0 flutter: plugin: From a6de03f94a97a057f6fd5bdc1f1d312c8a585c5d Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 28 Jul 2019 13:46:25 -0700 Subject: [PATCH 24/26] Fix test --- packages/firebase_auth/example/test/firebase_auth.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index 2118332bc5b7..21bbed0e1a2d 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -41,8 +41,10 @@ void main() { expect(tokenResult.issuedAtTime, isNotNull); // TODO(jackson): Fix behavior to be consistent across platforms // https://github.com/firebase/firebase-ios-sdk/issues/3445 - expect(tokenResult.signInProvider == null || - tokenResult.signInProvider == 'anonymous'); + expect( + tokenResult.signInProvider == null || + tokenResult.signInProvider == 'anonymous', + isTrue); expect(tokenResult.claims['provider_id'], 'anonymous'); expect(tokenResult.claims['firebase']['sign_in_provider'], 'anonymous'); expect(tokenResult.claims['user_id'], user.uid); From bbc890d8c86d43d1590b3f13b5527ff962480355 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 28 Jul 2019 13:54:50 -0700 Subject: [PATCH 25/26] revert project file --- .../example/ios/Runner.xcodeproj/project.pbxproj | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/cloud_firestore/example/ios/Runner.xcodeproj/project.pbxproj b/packages/cloud_firestore/example/ios/Runner.xcodeproj/project.pbxproj index c6de6cfc9729..80980c30cd85 100644 --- a/packages/cloud_firestore/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/cloud_firestore/example/ios/Runner.xcodeproj/project.pbxproj @@ -42,14 +42,12 @@ /* Begin PBXFileReference section */ 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; - 4B03A9F44CC8F2B171D99467 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 5C6F5A6F1EC3CCCC008D64B5 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 5C6F5A701EC3CCCC008D64B5 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 7A1ECC901E8EDB6900309407 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 7BF00BEAF1D6E989D08505A8 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; @@ -79,8 +77,6 @@ 840012C8B5EDBCF56B0E4AC1 /* Pods */ = { isa = PBXGroup; children = ( - 7BF00BEAF1D6E989D08505A8 /* Pods-Runner.debug.xcconfig */, - 4B03A9F44CC8F2B171D99467 /* Pods-Runner.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -246,13 +242,16 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-resources.sh", + "${PODS_CONFIGURATION_BUILD_DIR}/gRPC/gRPCCertificates.bundle", ); name = "[CP] Copy Pods Resources"; outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/gRPCCertificates.bundle", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; showEnvVarsInLog = 0; }; 95BB15E9E1769C0D146AA592 /* [CP] Embed Pods Frameworks */ = { @@ -261,13 +260,16 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${PODS_ROOT}/../.symlinks/flutter/ios-release/Flutter.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; 9740EEB61CF901F6004384FC /* Run Script */ = { From d5b84cc8a9bea2e8752a3b9e60a86e4dbdf8d901 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 28 Jul 2019 23:28:14 -0700 Subject: [PATCH 26/26] Fix some merge damage --- .../firebase_auth/example/test/firebase_auth.dart | 14 +++++++------- .../firebase_auth/test/firebase_auth_test.dart | 6 ------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index 6d6537100447..b08ac7927711 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -37,13 +37,6 @@ void main() { expect(user.isAnonymous, isTrue); expect(user.metadata.creationTime.isAfter(DateTime(2018, 1, 1)), isTrue); expect(user.metadata.creationTime.isBefore(DateTime.now()), isTrue); - await auth.signOut(); - final FirebaseUser user2 = (await auth.signInAnonymously()).user; - expect(user2.uid, isNot(equals(user.uid))); - expect(user2.metadata.creationTime.isBefore(user.metadata.creationTime), - isFalse); - expect( - user2.metadata.lastSignInTime, equals(user2.metadata.creationTime)); final IdTokenResult tokenResult = await user.getIdToken(); expect(tokenResult.token, isNotNull); expect(tokenResult.expirationTime.isAfter(DateTime.now()), isTrue); @@ -58,6 +51,13 @@ void main() { expect(tokenResult.claims['provider_id'], 'anonymous'); expect(tokenResult.claims['firebase']['sign_in_provider'], 'anonymous'); expect(tokenResult.claims['user_id'], user.uid); + await auth.signOut(); + final FirebaseUser user2 = (await auth.signInAnonymously()).user; + expect(user2.uid, isNot(equals(user.uid))); + expect(user2.metadata.creationTime.isBefore(user.metadata.creationTime), + isFalse); + expect( + user2.metadata.lastSignInTime, equals(user2.metadata.creationTime)); }); test('isSignInWithEmailLink', () async { diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 8751931371b1..5573302c62b6 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -32,12 +32,6 @@ const Map kMockIdTokenResultClaims = { const int kMockIdTokenResultExpirationTimestamp = 123456; const int kMockIdTokenResultAuthTimestamp = 1234567; const int kMockIdTokenResultIssuedAtTimestamp = 12345678; -const Map kMockAdditionalUserInfo = { - 'isNewUser': false, - 'username': 'flutterUser', - 'providerId': 'testProvider', - 'profile': {'foo': 'bar'}, -}; const Map kMockIdTokenResult = { 'token': kMockIdToken, 'expirationTimestamp': kMockIdTokenResultExpirationTimestamp,