Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 990b35a

Browse files
committed
adding support auth link for Twitter
* Link federated Twitter auth provider credentials to a user account. * This fix calls method ```linkWithCredential()``` like other providers (facebook, google).
1 parent eff94c1 commit 990b35a

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

packages/firebase_auth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Added support for `updatePassword` in `FirebaseUser`.
44
* **Breaking Change** Moved `updateEmail` and `updateProfile` to `FirebaseUser`.
55
This brings the `firebase_auth` package inline with other implementations and documentation.
6+
* Adding support for linkWithTwitterCredential in FirebaseAuth.
67

78
## 0.5.20
89

packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public void onMethodCall(MethodCall call, Result result) {
111111
case "linkWithFacebookCredential":
112112
handleLinkWithFacebookCredential(call, result);
113113
break;
114+
case "linkWithTwitterCredential":
115+
handleLinkWithTwitterCredential(call, result);
116+
break;
114117
case "updateEmail":
115118
handleUpdateEmail(call, result);
116119
break;
@@ -376,6 +379,18 @@ private void handleLinkWithFacebookCredential(MethodCall call, final Result resu
376379
.addOnCompleteListener(new SignInCompleteListener(result));
377380
}
378381

382+
private void handleLinkWithTwitterCredential(MethodCall call, final Result result) {
383+
@SuppressWarnings("unchecked")
384+
Map<String, String> arguments = (Map<String, String>) call.arguments;
385+
String authToken = arguments.get("authToken");
386+
String authTokenSecret = arguments.get("authTokenSecret");
387+
AuthCredential credential = TwitterAuthProvider.getCredential(authToken, authTokenSecret);
388+
firebaseAuth
389+
.getCurrentUser()
390+
.linkWithCredential(credential)
391+
.addOnCompleteListener(new SignInCompleteListener(result));
392+
}
393+
379394
private void handleSignInWithFacebook(MethodCall call, final Result result) {
380395
@SuppressWarnings("unchecked")
381396
Map<String, String> arguments = (Map<String, String>) call.arguments;

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
176176
completion:^(FIRUser *user, NSError *error) {
177177
[self sendResult:result forUser:user error:error];
178178
}];
179+
} else if ([@"linkWithTwitterCredential" isEqualToString:call.method]) {
180+
NSString *authToken = call.arguments[@"authToken"];
181+
NSString *authTokenSecret = call.arguments[@"authTokenSecret"];
182+
FIRAuthCredential *credential =
183+
[FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret];
184+
[[FIRAuth auth].currentUser linkWithCredential:credential
185+
completion:^(FIRUser *user, NSError *error) {
186+
[self sendResult:result forUser:user error:error];
187+
}];
179188
} else if ([@"updateEmail" isEqualToString:call.method]) {
180189
NSString *email = call.arguments[@"email"];
181190
[[FIRAuth auth].currentUser updateEmail:email
@@ -188,6 +197,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
188197
completion:^(NSError *error) {
189198
[self sendResult:result forUser:nil error:error];
190199
}];
200+
191201
} else if ([@"updateProfile" isEqualToString:call.method]) {
192202
FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest];
193203
if (call.arguments[@"displayName"]) {

packages/firebase_auth/lib/firebase_auth.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,21 @@ class FirebaseAuth {
434434
return currentUser;
435435
}
436436

437+
Future<FirebaseUser> linkWithTwitterCredential({
438+
@required String authToken,
439+
@required String authTokenSecret,
440+
}) async {
441+
final Map<dynamic, dynamic> data = await channel.invokeMethod(
442+
'linkWithTwitterCredential',
443+
<String, String>{
444+
'authToken': authToken,
445+
'authTokenSecret': authTokenSecret,
446+
},
447+
);
448+
final FirebaseUser currentUser = FirebaseUser._(data);
449+
return currentUser;
450+
}
451+
437452
/// Sets the user-facing language code for auth operations that can be
438453
/// internationalized, such as [sendEmailVerification]. This language
439454
/// code should follow the conventions defined by the IETF in BCP47.

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 <flutter-dev@googlegroups.com>
66
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth
7-
version: 0.5.20
7+
version: 0.6.0
88

99
flutter:
1010
plugin:

packages/firebase_auth/test/firebase_auth_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const String kMockEmail = 'test@example.com';
1616
const String kMockPassword = 'passw0rd';
1717
const String kMockIdToken = '12345';
1818
const String kMockAccessToken = '67890';
19+
const String kMockAuthToken = '23456';
20+
const String kMockAuthTokenSecret = '78901';
1921
const String kMockCustomToken = '12345';
2022
const String kMockPhoneNumber = '5555555555';
2123
const String kMockVerificationId = '12345';
@@ -246,6 +248,26 @@ void main() {
246248
);
247249
});
248250

251+
test('linkWithTwitterCredential', () async {
252+
final FirebaseUser user = await auth.linkWithTwitterCredential(
253+
authToken: kMockAuthToken,
254+
authTokenSecret: kMockAuthTokenSecret,
255+
);
256+
verifyUser(user);
257+
expect(
258+
log,
259+
<Matcher>[
260+
isMethodCall(
261+
'linkWithTwitterCredential',
262+
arguments: <String, String>{
263+
'authToken': kMockAuthToken,
264+
'authTokenSecret': kMockAuthTokenSecret,
265+
},
266+
),
267+
],
268+
);
269+
});
270+
249271
test('signInWithFacebook', () async {
250272
final FirebaseUser user = await auth.signInWithFacebook(
251273
accessToken: kMockAccessToken,

0 commit comments

Comments
 (0)