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.9.0

* **Breaking change**: `PhoneVerificationCompleted` now provides an `AuthCredential` that can
be used with `signInWithCredential` or `linkWithCredential` instead of signing in automatically.
* **Breaking change**: Remove internal counter `nextHandle` from public API.

## 0.8.4+5

* Increase Firebase/Auth CocoaPod dependency to '~> 5.19'.
Expand Down
1 change: 1 addition & 0 deletions packages/firebase_auth/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ android {
}
dependencies {
api 'com.google.firebase:firebase-auth:16.0.5'
api 'com.google.code.gson:gson:2.8.5'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.firebase.auth.TwitterAuthProvider;
import com.google.firebase.auth.UserInfo;
import com.google.firebase.auth.UserProfileChangeRequest;
import com.google.gson.Gson;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
Expand Down Expand Up @@ -189,19 +190,11 @@ private void handleVerifyPhoneNumber(
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
firebaseAuth
.signInWithCredential(phoneAuthCredential)
.addOnCompleteListener(
new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Map<String, Object> arguments = new HashMap<>();
arguments.put("handle", handle);
channel.invokeMethod("phoneVerificationCompleted", arguments);
}
}
});
Map<String, Object> arguments = new HashMap<>();
arguments.put("handle", handle);
String parsedJson = new Gson().toJson(phoneAuthCredential);
arguments.put("phoneAuthCredential", parsedJson);
channel.invokeMethod("phoneVerificationCompleted", arguments);
}

@Override
Expand Down Expand Up @@ -453,9 +446,13 @@ private AuthCredential getCredential(Map<String, Object> arguments) {
}
case PhoneAuthProvider.PROVIDER_ID:
{
String accessToken = data.get("verificationId");
String smsCode = data.get("smsCode");
credential = PhoneAuthProvider.getCredential(accessToken, smsCode);
if (data.containsKey("verificationId")) {
String accessToken = data.get("verificationId");
String smsCode = data.get("smsCode");
credential = PhoneAuthProvider.getCredential(accessToken, smsCode);
} else {
credential = new Gson().fromJson(data.get("jsonObject"), PhoneAuthCredential.class);
}
break;
}
default:
Expand Down
5 changes: 3 additions & 2 deletions packages/firebase_auth/example/lib/signin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,10 @@ class _PhoneSignInSectionState extends State<_PhoneSignInSection> {
_message = '';
});
final PhoneVerificationCompleted verificationCompleted =
(FirebaseUser user) {
(AuthCredential phoneAuthCredential) {
_auth.signInWithCredential(phoneAuthCredential);
setState(() {
_message = 'signInWithPhoneNumber auto succeeded: $user';
_message = 'Received phone auth credential: $phoneAuthCredential';
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ class PhoneAuthProvider {
'smsCode': smsCode,
});
}

// PhoneAuthProvider uses JSON serialization on Android when the SMS code was
// detected automatically.
static AuthCredential _getCredentialFromObject({
@required String jsonObject,
}) {
return AuthCredential._(providerId, <String, String>{
"jsonObject": jsonObject,
});
}
}
16 changes: 9 additions & 7 deletions packages/firebase_auth/lib/src/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

part of firebase_auth;

typedef void PhoneVerificationCompleted(FirebaseUser firebaseUser);
typedef void PhoneVerificationCompleted(AuthCredential phoneAuthCredential);
typedef void PhoneVerificationFailed(AuthException error);
typedef void PhoneCodeSent(String verificationId, [int forceResendingToken]);
typedef void PhoneCodeAutoRetrievalTimeout(String verificationId);
Expand Down Expand Up @@ -32,7 +32,7 @@ class FirebaseAuth {
final Map<int, StreamController<FirebaseUser>> _authStateChangedControllers =
<int, StreamController<FirebaseUser>>{};

static int nextHandle = 0;
static int _nextHandle = 0;
final Map<int, Map<String, dynamic>> _phoneAuthCallbacks =
<int, Map<String, dynamic>>{};

Expand Down Expand Up @@ -317,7 +317,8 @@ class FirebaseAuth {
///
/// [verificationCompleted] This callback must be implemented.
/// It will trigger when an SMS is auto-retrieved or the phone number has
/// been instantly verified. The callback will provide a [FirebaseUser].
/// been instantly verified. The callback will receive an [AuthCredential]
/// that can be passed to [signInWithCredential] or [linkWithCredential].
///
/// [verificationFailed] This callback must be implemented.
/// Triggered when an error occurred during phone number verification.
Expand All @@ -344,11 +345,11 @@ class FirebaseAuth {
'PhoneCodeSent': codeSent,
'PhoneCodeAuthRetrievalTimeout': codeAutoRetrievalTimeout,
};
nextHandle += 1;
_phoneAuthCallbacks[nextHandle] = callbacks;
_nextHandle += 1;
_phoneAuthCallbacks[_nextHandle] = callbacks;

final Map<String, dynamic> params = <String, dynamic>{
'handle': nextHandle,
'handle': _nextHandle,
'phoneNumber': phoneNumber,
'timeout': timeout.inMilliseconds,
'forceResendingToken': forceResendingToken,
Expand Down Expand Up @@ -472,7 +473,8 @@ class FirebaseAuth {
final int handle = call.arguments['handle'];
final PhoneVerificationCompleted verificationCompleted =
_phoneAuthCallbacks[handle]['PhoneVerificationCompleted'];
verificationCompleted(await currentUser());
verificationCompleted(PhoneAuthProvider._getCredentialFromObject(
jsonObject: call.arguments["phoneAuthCredential"].toString()));
break;
case 'phoneVerificationFailed':
final int handle = call.arguments['handle'];
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.8.4+5"
version: "0.9.0"

flutter:
plugin:
Expand Down