-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[firebase_auth] Enable passwordless sign in #1159
[firebase_auth] Enable passwordless sign in #1159
Conversation
…ndLink in Flutter, iOS
…nWithEmailAndLink
Thanks for the contribution! I don't think I have enough context in the plugin to really review this. Added @kroikie and @collinjackson. |
Hi @bizz84 Thank you for the contribution! Is receiving a dynamic link the only native code that a user would have to include? There is already an official firebase_dynamic_links plugin that can probably handle that portion for you. Also, As we currently don't have a harness for testing the platform side of plugins, current and new features are not properly covered by tests. In order to maintain a quality bar for flutter/plugins we are going to avoid adding new features that aren't critical until they can be properly tested. The test harness work is tracked in flutter/flutter#10824 and flutter/flutter#26080, your feedback on the testing work will be really appreciated (will it properly support the testing needs of this PR?) some design details should be available on flutter/flutter#10824 soon(contributions to that effort are welcomed!). |
Hi @bparrishMines, Thank you for pointing me at the firebase_dynamic_links plugin. I have tried to integrate this plugin in my code, and I believe the functionality offered is not sufficient in my use case. The plugin can be used to retrieve a deep link url if the app was started from a dynamic link. However, I also need to detect if dynamic links that are opened while the app is running. This is the most common use case with passwordless sign-in as the user goes from the app to the email client and back to the (still running) app. My own implementation supports this by with a stream-based API on the Flutter side, so that I can handle each dynamic link as an event. The current API for firebase_dynamic_links is future-based only. It would be great if firebase_dynamic_links could support this use case with a stream-based API. Could you suggest what would be the best way forward on this? I assume a PR to the plugins repo would be the way to go? The platform code for firebase_dynamic_links is not straightforward to me. Perhaps someone from the team could help out? Regarding your comments about flutter/flutter#10824, I agree that some testing for this would be appropriate. I feel that end-to-end testing would be very valuable as a way of assuring that the entire flow works. At the same time, passwordless sign-in is a use case that requires project-level configuration on Firebase, and I'm not sure how this could be brought into a test harness. Perhaps this can be explored in more detail once we have a candidate PR for firebase_dynamic_links? |
… versions of iOS SDK
…e-passwordless-sign-in
Should probably be done with |
@bizz84 I was able to receive dynamic links even while the app was already open. I did this by using the WidgetsBindingObserver. I added an example to this PR. The reason we wouldn't go with a stream is because receiving links on android doesn't use one. You just call We try to have the dart API match the Android and iOS APIs despite plugins being asynchronous. |
@bparrishMines I agree with your implementation. I have tested this with dynamic links and widgets binding on another project and it works well. As a bonus, with this approach a Flutter-only solution can be implemented without any host code. I think with the latest changes we should be able to merge this. |
@creativecreatorormaybenot the standard email & password auth call doesn't use |
I forgot to add the dependency to the |
@bizz84 @creativecreatorormaybenot From my understanding of the email and link flow, this PR deals with signing up a User, while I'm not an expert with using FirebaseAuth, but here is the documentation provided by the Firebase console when using email authentication; Android & iOS. Both implementations seem to be needed. In a separate PR we would probably just add another static method like the Android API. class EmailAuthProvider {
static const String providerId = 'password';
static AuthCredential getCredential({
String email,
String password,
}) {
return AuthCredential._(providerId, <String, String>{
'email': email,
'password': password,
});
}
static AuthCredential getCredentialWithLink({
String email,
String link,
}) {
return AuthCredential._(providerId, <String, String>{
'email': email,
'link': link,
});
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM since it works with firebase_dynamic_links.
We should also probably also get an LGTM from @kroikie since he is a code owner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I added some dartdocs and updated CHANGELOG/pubspec.yaml
I'd love to integration test this, because email is involved it may require out of process testing that can talk to other apps on the device. Support for that sort of test shouldn't hold back merging.
We do need a unit test, though. |
After some debate I renamed the API @bparrishMines can you take a quick look at the tests I added and let me know if you agree that this change is ready to merge? |
@collinjackson Now, we are definitely missing the |
Thanks, @creativecreatorormaybenot. Can you please update this PR to include an implementation of linking using a credential? I think we can keep the |
@collinjackson I am not exactly sure how to achieve it because it seems like the action code has to be extracted using Dynamic Links: https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/authcredential.js#L977
It would be very helpful to know what the native libraries require, but as far as I can tell, there is no way to get access to that source code. |
@creativecreatorormaybenot if I go ahead and merge this PR and are you willing to add |
Here is the iOS source for dynamic links and messaging if it's useful: https://github.com/firebase/firebase-ios-sdk/tree/master/Firebase/Messaging |
@collinjackson Sure. However, I will just do it without the credential for now. |
* Implement sendLinkToEmail, isSignInWithEmailLink and signInWithEmailAndLink in Flutter
This PR adds the missing code to interface with the native APIs to send and handle email links.
This consists of the following Dart methods:
Future<dynamic> sendLinkToEmail({ @required String email, @required String url, @required bool handleCodeInApp, @required String iOSBundleID, @required String androidPackageName, @required bool androidInstallIfNotAvailable, @required String androidMinimumVersion, String dynamicLinkDomain })
Future<bool> isSignInWithEmailLink({String link})
Future<FirebaseUser> signInWithEmailAndLink({String email, String link})
This is enough to tap into the underlying iOS and Android APIs from Firebase Auth.
Done as part of this PR
I propose that this PR is merged so that client apps have access to the required native APIs.
Future work
Additional native code is needed to handle the incoming dynamic links and pass these back to Flutter.
I have implemented a demo app that shows a full email link activation flow here:
https://github.com/bizz84/passwordless_sign_in_firebase_flutter
However, client apps should not need to write additional native code to get this sign-in flow working.
Hence, I propose either of the following:
firebase_auth
, or