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

adding support auth link for Twitter #697

Merged
merged 2 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.1

* Adding support for linkWithTwitterCredential in FirebaseAuth.

## 0.6.0

* Added support for `updatePassword` in `FirebaseUser`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> arguments = (Map<String, String>) 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<String, String> arguments = (Map<String, String>) call.arguments;
Expand Down
10 changes: 10 additions & 0 deletions packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]) {
Expand Down
15 changes: 15 additions & 0 deletions packages/firebase_auth/lib/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,21 @@ class FirebaseAuth {
return currentUser;
}

Future<FirebaseUser> linkWithTwitterCredential({
@required String authToken,
@required String authTokenSecret,
}) async {
final Map<dynamic, dynamic> data = await channel.invokeMethod(
'linkWithTwitterCredential',
<String, String>{
'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.
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
like Google, Facebook and Twitter.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth
version: 0.5.20
version: 0.6.0

flutter:
plugin:
Expand Down
22 changes: 22 additions & 0 deletions packages/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -246,6 +248,26 @@ void main() {
);
});

test('linkWithTwitterCredential', () async {
final FirebaseUser user = await auth.linkWithTwitterCredential(
authToken: kMockAuthToken,
authTokenSecret: kMockAuthTokenSecret,
);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'linkWithTwitterCredential',
arguments: <String, String>{
'authToken': kMockAuthToken,
'authTokenSecret': kMockAuthTokenSecret,
},
),
],
);
});

test('signInWithFacebook', () async {
final FirebaseUser user = await auth.signInWithFacebook(
accessToken: kMockAccessToken,
Expand Down