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

Add phone auth #606

Merged
merged 9 commits into from
Jul 17, 2018
Merged

Add phone auth #606

merged 9 commits into from
Jul 17, 2018

Conversation

kroikie
Copy link
Contributor

@kroikie kroikie commented Jun 7, 2018

Update firebase_auth plugin to support phone number authentication.

This PR is a combination of the ideas expressed by @alibitek in PR and @pranjalsatija in PR

Fixes: flutter/flutter#10404

@pranjalsatija
Copy link

@kroikie looks good. Sorry about the formatting issue. I'm having some serious compatibility issues with my computer after upgrading to Mojave.

@pranjalsatija
Copy link

@kroikie Should we also add a corresponding phoneNumber field to FirebaseUser?

@kroikie
Copy link
Contributor Author

kroikie commented Jun 11, 2018

@pranjalsatija good call, added.

@kroikie kroikie changed the title [WIP] Add phone auth Add phone auth Jun 11, 2018
@mmcc007
Copy link

mmcc007 commented Jun 15, 2018

I tested it on an armv7 (32-bit) iPhone and an android simulator and the example provided worked fine. Nice work.

checked out the PR using

git fetch origin pull/606/head:mybranch
git checkout mybranch

Note have to add phone number +1 408-555-6969 and verifier 888888 to whitelist in Google Console if testing provided example on your own Google project (in addition to the usual handling of google-services.json and GoogleService-Info.plist).

To add it to your own flutter project and see how far you can get, add the following to your pubspec.yaml:

  firebase_auth:
    git:
      url: git@github.com:flutter/plugins.git
      path: packages/firebase_auth
      ref: 075897e

Happy Coding!!

@hemesh2394
Copy link

Is firebase auth v 0.5.12 is released?
how i can implement to my project?

@mmcc007
Copy link

mmcc007 commented Jun 15, 2018

@hemesh2394 As of this posting, firebase auth v 0.5.12 has not yet been released. This Pull Request tracks the process to release. firebase auth v 0.5.12 is currently considered implemented and must go thru a review process before being released (additional development and review may occur before being released). In the meantime, if you wish to experiment with the new phone feature prior to release, you can use the current (unreleased as of this posting) version by following my suggestion in prior post.

@saivamsid
Copy link

@mmcc007 how much time will it take for the release of firebase auth v 0.5.12. Thanks

@mmcc007
Copy link

mmcc007 commented Jun 16, 2018

@saivamsid I'm not a contributor to this new feature. Just looking at using the new phone auth feature in a flutter app. So I have no input on when it will be released.

@gildaswise
Copy link

@mmcc007 How did you manage to get the iOS working? Here it just stopped sending the phone verification today on a real device while the simulator still works.

@Hixie
Copy link
Contributor

Hixie commented Jun 26, 2018

cc @bparrishMines for review

@mmcc007
Copy link

mmcc007 commented Jun 27, 2018

@gildaswise I tested it again on an armv7 (32-bit) iPhone and it still works (deleted the user in Google Console -> Authentication). It looks like it will not work without using a normalized phone number (probably conforming to format described in libphonenumber). For example, in my case (in USA) it did not send a verification code if I used the format 14085556969 but did when I used the format +14085556969.

BTW: would be nice if there was a dart implementation of libphonenumber to catch badly formed phone numbers on input (hint... hint... ;) )

@bparrishMines bparrishMines self-requested a review June 27, 2018 16:52
@gildaswise
Copy link

gildaswise commented Jun 27, 2018

@mmcc007 I don't know what's happening here. I'm using the same number on both simulator and real device (an iPhone 7+) and it is only working on the simulator. This is the only thing missing for a release here. The only difference is that I'm brazilian, so the country code is +55.

@mmcc007
Copy link

mmcc007 commented Jun 27, 2018

@gildaswise I assume you are using your real iPhone 7+'s phone number on your real iPhone 7+. Try texting (or have someone from another country text) your real iPhone 7+ using an inbound international format to confirm you are using the correct format for your real iPhone 7+

Per Telephone_numbers_in_Brazil I'm guessing the format should look something like 011 55 aa nnnn nnnn. My guess is to try it without the spaces, so for example for Rio de Janeiro (area code 21) it would be 011552155555555. Worth a try.

@gildaswise
Copy link

@mmcc007 That didn't work, sadly. As I said, it's only failing on the iPhone 7+ while it works normally with this format: +55 (21) 95555-5555 parsed like this: +5521955555555 on the Android side or the iOS simulator (SE or 8+)

@mmcc007
Copy link

mmcc007 commented Jun 27, 2018

@gildaswise Working on a simulator confirms that the code is most likely completely correct.

If you cannot receive a text on your real device from whichever data center Google is texting your confirmation code (datacenter could be in Brazil, or some other country), then, I'm guessing, either you cannot receive international texts on your real device, or the format of the number is incorrect, or possibly something else.

Confirm u can receive international texts on your real device and try different phone number formats, I'm guessing it should eventually work.

@gildaswise
Copy link

@mmcc007 I tried sending the code to the iPhone 7+'s number from my Google Pixel and it worked. I really don't know what is the problem as all printed logs from inputted numbers are matching.

@mmcc007
Copy link

mmcc007 commented Jun 27, 2018

My guess is that your real device has to have a plan from your telephone company that supports international texting.

@gildaswise
Copy link

I said that it's receiving the code if I do the process from my Android device or the simultator, but it isn't "sending from itself".

@mmcc007
Copy link

mmcc007 commented Jun 27, 2018

@gildaswise I assume from your posts that the phone auth of your flutter app works on your real Android device but not on your real iPhone device (in addition to your iPhone simulator). I can confirm I made no special changes for my real iPhone device. It worked first time after it worked on my android simulator.

If both your real iPhone and Android devices have a plan that supports international texting, then I don't know off the top of my head, why you can receive confirmation codes on your real Android device but not on your real iPhone device.

My guess is you're pretty close to solving the problem. I don't know if there is much further I can add.

default:
result.notImplemented();
break;
}
}

private void handleSignInWithPhoneNumber(MethodCall call, Result result) {
Map<String, String> arguments = (Map<String, String>) call.arguments;
String verificationId = arguments.get("verificationId");
Copy link
Contributor

@bparrishMines bparrishMines Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can just use call.argument("verificationId")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast to Map<String, String> would still be necessary so I'll leave it as is.

@@ -37,6 +37,10 @@ class MyHomePage extends StatefulWidget {

class _MyHomePageState extends State<MyHomePage> {
Future<String> _message = new Future<String>.value('');
TextEditingController smsCodeController = new TextEditingController();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add underscore to variables like _message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@kueckermann
Copy link

kueckermann commented Jul 16, 2018

@AlexandreRoba Have you tried using https instead of ssh? It fixed some fetch issues for me.

firebase_auth:
    git:
      url: https://github.com/flutter/plugins.git
      path: packages/firebase_auth
      ref: 000cd4c7f8b9eba0feef714a08ff8a13f0f81990

@AlexandreRoba
Copy link

Hello @kueckermann thanks for the tip. It solved the issue. Now why it works on my mac and not in a docker container is mistery :). Cheers, Alex.

@kroikie kroikie force-pushed the add-phone-auth branch 2 times, most recently from 471373c to 5e5e346 Compare July 17, 2018 00:08
@kroikie kroikie merged commit 6f6d15c into flutter:master Jul 17, 2018
@xzminx
Copy link

xzminx commented Jul 17, 2018

I tried out the PR, and it worked fine at first - I got the SMS, entered code and logged in.
Next time I tried to login, it would be an instant login. Worked fine, FirebaseUser gets returned.

Then i tried deleting the FirebaseUser from the console for my phone number.
Next time I try to login in the app (android), I call verifyPhoneNumber() and the verificationCompleted callback is triggered, but the FirebaseUser that is passed is null. I cannot get it to work. I tried signing out but it had no effect.

Any comments on this?

@kroikie
Copy link
Contributor Author

kroikie commented Jul 18, 2018

@xzminx Thanks for reporting this, I was able to reproduce and I will submit a fix in another PR.

@kroikie
Copy link
Contributor Author

kroikie commented Jul 18, 2018

@xzminx fix for this issue is available in PR

kmorkos pushed a commit to kmorkos/plugins that referenced this pull request Jul 19, 2018
@probuse
Copy link

probuse commented Jul 28, 2018

@kueckermann I am getting
fatal: bad object 000cd4c7f8b9eba0feef714a08ff8a13f0f81990
What should i use for the ref part?
When i use ssh i get:

Permission denied (publickey).
fatal: Could not read from remote repository.

How can i add the dependency for the PR in my flutter project,
Thank you

@kroikie
Copy link
Contributor Author

kroikie commented Jul 30, 2018

@probuse Phone Auth has been published in the firebase_auth plugin.

@saltpetre
Copy link

saltpetre commented Jul 30, 2018

@gildaswise If you have a chance can you please update your medium article with 0.5.15. Thanks

@gildaswise
Copy link

@saltpetreca Just updated it! Also, changed a few things related to error handling.

@saltpetre
Copy link

@gildaswise Thanks Appreciate

@padmanabanSampath
Copy link

@gildaswise & @kroikie
How to persist the user data for certain period in phone auth, even if the user closes the app?

@CasperPas
Copy link

@padmanabanSampath you can use shared_preferences plugin

@padmanabanSampath
Copy link

@CasperPas thanks for your recommendation, any example code snippet will be useful, regarding phone auth token or uid persistence and checking whether the user has signed in before or not, and adding expiry to the shared preference firebase user storage

@shriharip
Copy link

I am sorry if this is not the right place to raise this issue again. Just opened the issue on flutter (flutter/flutter#22903 ) but was looking for any help!?.

Is a google or any other auth necessary for phone auth or can it be done stand alone. If it can be done stand alone what is the above error message.

˜Thanks

julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.