Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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
6 changes: 6 additions & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.11.0

* **Breaking change**: `linkWithCredential` is now a function of `FirebaseUser`instead of
`FirebaseAuth`.
* Added test for newer `linkWithCredential` function.

## 0.10.0+1

* Increase Firebase/Auth CocoaPod dependency to '~> 6.0'.
Expand Down
33 changes: 0 additions & 33 deletions packages/firebase_auth/lib/src/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,39 +417,6 @@ class FirebaseAuth {
return currentUser;
}

/// Associates a user account from a third-party identity provider with this
/// user and returns additional identity provider data.
///
/// This allows the user to sign in to this account in the future with
/// the given account.
///
/// Errors:
/// • `ERROR_WEAK_PASSWORD` - If the password is not strong enough.
/// • `ERROR_INVALID_CREDENTIAL` - If the credential is malformed or has expired.
/// • `ERROR_CREDENTIAL_ALREADY_IN_USE` - If the account is already in use by a different account.
/// • `ERROR_USER_DISABLED` - If the user has been disabled (for example, in the Firebase console)
/// • `ERROR_REQUIRES_RECENT_LOGIN` - If the user's last sign-in time does not meet the security threshold. Use reauthenticate methods to resolve.
/// • `ERROR_PROVIDER_ALREADY_LINKED` - If the current user already has an account of this type linked.
/// • `ERROR_OPERATION_NOT_ALLOWED` - Indicates that this type of account is not enabled.
/// • `ERROR_INVALID_ACTION_CODE` - If the action code in the link is malformed, expired, or has already been used.
/// This can only occur when using [EmailAuthProvider.getCredentialWithLink] to obtain the credential.
Future<FirebaseUser> linkWithCredential(AuthCredential credential) async {
assert(credential != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await channel.invokeMethod(
'linkWithCredential',
<String, dynamic>{
'app': app.name,
'provider': credential._provider,
'data': credential._data,
},
);
final FirebaseUser currentUser = FirebaseUser._(data, app);
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
33 changes: 33 additions & 0 deletions packages/firebase_auth/lib/src/firebase_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,39 @@ class FirebaseUser extends UserInfo {
});
}

/// Associates a user account from a third-party identity provider with this
/// user and returns additional identity provider data.
///
/// This allows the user to sign in to this account in the future with
/// the given account.
///
/// Errors:
/// • `ERROR_WEAK_PASSWORD` - If the password is not strong enough.
/// • `ERROR_INVALID_CREDENTIAL` - If the credential is malformed or has expired.
/// • `ERROR_CREDENTIAL_ALREADY_IN_USE` - If the account is already in use by a different account.
/// • `ERROR_USER_DISABLED` - If the user has been disabled (for example, in the Firebase console)
/// • `ERROR_REQUIRES_RECENT_LOGIN` - If the user's last sign-in time does not meet the security threshold. Use reauthenticate methods to resolve.
/// • `ERROR_PROVIDER_ALREADY_LINKED` - If the current user already has an account of this type linked.
/// • `ERROR_OPERATION_NOT_ALLOWED` - Indicates that this type of account is not enabled.
/// • `ERROR_INVALID_ACTION_CODE` - If the action code in the link is malformed, expired, or has already been used.
/// This can only occur when using [EmailAuthProvider.getCredentialWithLink] to obtain the credential.
Future<FirebaseUser> linkWithCredential(AuthCredential credential) async {
assert(credential != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await FirebaseAuth.channel.invokeMethod(
'linkWithCredential',
<String, dynamic>{
'app': _app.name,
'provider': credential._provider,
'data': credential._data,
},
);
final FirebaseUser currentUser = FirebaseUser._(data, _app);
return currentUser;
}

/// Initiates email verification for the user.
Future<void> sendEmailVerification() async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
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 <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth
version: "0.10.0+1"
version: "0.11.0"

flutter:
plugin:
Expand Down
81 changes: 72 additions & 9 deletions packages/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,18 @@ void main() {
email: '[email protected]',
link: '<Url with domain from your Firebase project>',
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down Expand Up @@ -294,11 +301,18 @@ void main() {
authToken: kMockIdToken,
authTokenSecret: kMockAccessToken,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down Expand Up @@ -343,11 +357,18 @@ void main() {
final AuthCredential credential = GithubAuthProvider.getCredential(
token: kMockGithubToken,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down Expand Up @@ -390,11 +411,18 @@ void main() {
email: kMockEmail,
password: kMockPassword,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down Expand Up @@ -602,11 +630,18 @@ void main() {
idToken: kMockIdToken,
accessToken: kMockAccessToken,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand All @@ -626,11 +661,18 @@ void main() {
final AuthCredential credential = FacebookAuthProvider.getCredential(
accessToken: kMockAccessToken,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down Expand Up @@ -673,11 +715,18 @@ void main() {
authToken: kMockAuthToken,
authTokenSecret: kMockAuthTokenSecret,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down Expand Up @@ -722,11 +771,18 @@ void main() {
final AuthCredential credential = GithubAuthProvider.getCredential(
token: kMockGithubToken,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down Expand Up @@ -769,11 +825,18 @@ void main() {
email: kMockEmail,
password: kMockPassword,
);
final FirebaseUser user = await auth.linkWithCredential(credential);
FirebaseUser user = await auth.currentUser();
user = await user.linkWithCredential(credential);
verifyUser(user);
expect(
log,
<Matcher>[
isMethodCall(
'currentUser',
arguments: <String, dynamic>{
'app': auth.app.name,
},
),
isMethodCall(
'linkWithCredential',
arguments: <String, dynamic>{
Expand Down