diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index 661dad2eaf0e..74495aef68ee 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.1 + +* Adding support for linkWithTwitterCredential in FirebaseAuth. + ## 0.6.0 * Added support for `updatePassword` in `FirebaseUser`. 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 6cd765ca5453..5eccd3c5efdf 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 @@ -111,6 +111,9 @@ public void onMethodCall(MethodCall call, Result result) { case "linkWithFacebookCredential": handleLinkWithFacebookCredential(call, result); break; + case "linkWithTwitterCredential": + handleLinkWithTwitterCredential(call, result); + break; case "updateEmail": handleUpdateEmail(call, result); break; @@ -376,6 +379,18 @@ private void handleLinkWithFacebookCredential(MethodCall call, final Result resu .addOnCompleteListener(new SignInCompleteListener(result)); } + private void handleLinkWithTwitterCredential(MethodCall call, final Result result) { + @SuppressWarnings("unchecked") + Map arguments = (Map) call.arguments; + String authToken = arguments.get("authToken"); + String authTokenSecret = arguments.get("authTokenSecret"); + AuthCredential credential = TwitterAuthProvider.getCredential(authToken, authTokenSecret); + firebaseAuth + .getCurrentUser() + .linkWithCredential(credential) + .addOnCompleteListener(new SignInCompleteListener(result)); + } + private void handleSignInWithFacebook(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index ed2aa7126d4e..ca6edcc8e62e 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -176,6 +176,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completion:^(FIRUser *user, NSError *error) { [self sendResult:result forUser:user error:error]; }]; + } else if ([@"linkWithTwitterCredential" isEqualToString:call.method]) { + NSString *authToken = call.arguments[@"authToken"]; + NSString *authTokenSecret = call.arguments[@"authTokenSecret"]; + FIRAuthCredential *credential = + [FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret]; + [[FIRAuth auth].currentUser linkWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"updateEmail" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; [[FIRAuth auth].currentUser updateEmail:email @@ -188,6 +197,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completion:^(NSError *error) { [self sendResult:result forUser:nil error:error]; }]; + } else if ([@"updateProfile" isEqualToString:call.method]) { FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest]; if (call.arguments[@"displayName"]) { diff --git a/packages/firebase_auth/lib/firebase_auth.dart b/packages/firebase_auth/lib/firebase_auth.dart index cc4907c20e5f..7020bdefe7f1 100755 --- a/packages/firebase_auth/lib/firebase_auth.dart +++ b/packages/firebase_auth/lib/firebase_auth.dart @@ -434,6 +434,21 @@ class FirebaseAuth { return currentUser; } + Future linkWithTwitterCredential({ + @required String authToken, + @required String authTokenSecret, + }) async { + final Map data = await channel.invokeMethod( + 'linkWithTwitterCredential', + { + 'authToken': authToken, + 'authTokenSecret': authTokenSecret, + }, + ); + final FirebaseUser currentUser = FirebaseUser._(data); + return currentUser; + } + /// Sets the user-facing language code for auth operations that can be /// internationalized, such as [sendEmailVerification]. This language /// code should follow the conventions defined by the IETF in BCP47. diff --git a/packages/firebase_auth/pubspec.yaml b/packages/firebase_auth/pubspec.yaml index 0d80a597032a..72388180fc62 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.5.20 +version: 0.6.0 flutter: plugin: diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 8c81d01c02fd..06b0814ce052 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -16,6 +16,8 @@ const String kMockEmail = 'test@example.com'; const String kMockPassword = 'passw0rd'; const String kMockIdToken = '12345'; const String kMockAccessToken = '67890'; +const String kMockAuthToken = '23456'; +const String kMockAuthTokenSecret = '78901'; const String kMockCustomToken = '12345'; const String kMockPhoneNumber = '5555555555'; const String kMockVerificationId = '12345'; @@ -246,6 +248,26 @@ void main() { ); }); + test('linkWithTwitterCredential', () async { + final FirebaseUser user = await auth.linkWithTwitterCredential( + authToken: kMockAuthToken, + authTokenSecret: kMockAuthTokenSecret, + ); + verifyUser(user); + expect( + log, + [ + isMethodCall( + 'linkWithTwitterCredential', + arguments: { + 'authToken': kMockAuthToken, + 'authTokenSecret': kMockAuthTokenSecret, + }, + ), + ], + ); + }); + test('signInWithFacebook', () async { final FirebaseUser user = await auth.signInWithFacebook( accessToken: kMockAccessToken,