Skip to content

[firebase_auth] Confirm password reset #1744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ build/
.project
.classpath
.settings

**/.flutter-plugins-dependencies
4 changes: 4 additions & 0 deletions packages/firebase_auth/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.15.4

* Add support for confirmPasswordReset

## 0.15.3

* Add support for OAuth Authentication for iOS and Android to solve generic providers authentication.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public void onMethodCall(MethodCall call, Result result) {
case "setLanguageCode":
handleSetLanguageCode(call, result, getAuth(call));
break;
case "confirmPasswordReset":
handleConfirmPasswordReset(call, result, getAuth(call));
default:
result.notImplemented();
break;
Expand Down Expand Up @@ -694,6 +696,16 @@ private void handleSetLanguageCode(MethodCall call, Result result, FirebaseAuth
result.success(null);
}

private void handleConfirmPasswordReset(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String oobCode = arguments.get("oobCode");
String newPassword = arguments.get("newPassword");

firebaseAuth.confirmPasswordReset(oobCode, newPassword);
result.success(null);
}

private class SignInCompleteListener implements OnCompleteListener<AuthResult> {
private final Result result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
NSString *language = call.arguments[@"language"];
[[self getAuth:call.arguments] setLanguageCode:language];
[self sendResult:result forObject:nil error:nil];
} else if ([@"confirmPasswordReset" isEqualToString:call.method]) {
NSString *oobCode = call.arguments[@"oobCode"];
NSString *newPassword = call.arguments[@"newPassword"];
[[self getAuth:call.arguments] confirmPasswordResetWithCode:oobCode newPassword:newPassword];
[self sendResult:result forObject:nil error:nil];
} else {
result(FlutterMethodNotImplemented);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/firebase_auth/firebase_auth/lib/src/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,17 @@ class FirebaseAuth {
assert(language != null);
return FirebaseAuthPlatform.instance.setLanguageCode(app.name, language);
}

/// Completes the password reset process, given a confirmation code and new password.
///
/// Errors:
/// `EXPIRED_ACTION_CODE` - if the password reset code has expired.
/// `INVALID_ACTION_CODE` - if the password reset code is invalid. This can happen if the code is malformed or has already been used.
/// `USER_DISABLED` - if the user corresponding to the given password reset code has been disabled.
/// `USER_NOT_FOUND` - if there is no user corresponding to the password reset code. This may have happened if the user was deleted between when the code was issued and when this method was called.
/// `WEAK_PASSWORD` - if the new password is not strong enough.
Future<void> confirmPasswordReset(String oobCode, String newPassword) {
return FirebaseAuthPlatform.instance
.confirmPasswordReset(oobCode, newPassword);
}
}
2 changes: 1 addition & 1 deletion packages/firebase_auth/firebase_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
authentication using passwords, phone numbers and identity providers
like Google, Facebook and Twitter.
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth/firebase_auth
version: 0.15.3
version: 0.15.4

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const String kMockVerificationId = '12345';
const String kMockSmsCode = '123456';
const String kMockLanguage = 'en';
const String kMockIdTokenResultSignInProvider = 'password';
const String kMockOobCode = 'oobcode';
const Map<dynamic, dynamic> kMockIdTokenResultClaims = <dynamic, dynamic>{
'claim1': 'value1',
};
Expand Down Expand Up @@ -876,6 +877,11 @@ void main() {
await auth.setLanguageCode(kMockLanguage);
verify(mock.setLanguageCode(auth.app.name, kMockLanguage));
});

test('confirmPasswordReset', () async {
await auth.confirmPasswordReset(kMockOobCode, kMockPassword);
verify(mock.confirmPasswordReset(kMockOobCode, kMockPassword));
});
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.3

- Added `confirmPasswordReset`

## 1.1.2

- Remove the deprecated `author:` field from pubspec.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,8 @@ abstract class FirebaseAuthPlatform {
}) {
throw UnimplementedError('verifyPhoneNumber() is not implemented');
}

Future<void> confirmPasswordReset(String oobCode, String newPassword) {
throw UnimplementedError('confirmPasswordReset() is not implemented');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ class MethodChannelFirebaseAuth extends FirebaseAuthPlatform {
return channel.invokeMethod<void>('verifyPhoneNumber', params);
}

@override
Future<void> confirmPasswordReset(String oobCode, String newPassword) {
return channel.invokeMethod('confirmPasswordReset', <String, String>{
'oobCode': oobCode,
'newPassword': newPassword,
});
}

Future<void> _callHandler(MethodCall call) async {
switch (call.method) {
case 'onAuthStateChanged':
Expand Down Expand Up @@ -468,7 +476,7 @@ PlatformIdTokenResult _decodeIdTokenResult(Map<String, dynamic> data) {
);
}

/// A utilily class that collects the callbacks for a [verifyPhoneNumber] call.
/// A utility class that collects the callbacks for a [verifyPhoneNumber] call.
class _PhoneAuthCallbacks {
const _PhoneAuthCallbacks(
this.verificationCompleted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the firebase_auth plugin.
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth/firebase_auth_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.1.2
version: 1.1.3

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const String kMockVerificationId = '12345';
const String kMockSmsCode = '123456';
const String kMockLanguage = 'en';
const String kMockIdTokenResultSignInProvider = 'password';
const String kMockOobCode = 'oobcode';
const Map<dynamic, dynamic> kMockIdTokenResultClaims = <dynamic, dynamic>{
'claim1': 'value1',
};
Expand Down Expand Up @@ -1335,6 +1336,23 @@ void main() {
],
);
});

test('confirmPasswordReset', () async {
await auth.confirmPasswordReset(kMockOobCode, kMockPassword);

expect(
log,
<Matcher>[
isMethodCall(
'confirmPasswordReset',
arguments: <String, String>{
'oobCode': kMockOobCode,
'newPassword': kMockPassword,
},
),
],
);
});
});
}

Expand Down