flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [Firebase_Auth] reCaptcha page pops even though play integrity configured

Open lironzemingo opened this issue 3 years ago • 132 comments

I have added Firebase auth to my app, configured AppCheck with Play integrity, added SHA-1 in Settings, added my SHA-256 (in Firebase console -> settings, and also under Play Integrity), and also my debug token. this code runs before runApp :

WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); await FirebaseAppCheck.instance.activate( webRecaptchaSiteKey: 'recaptcha-v3-site-key', androidProvider: _isDevEnvironment() ? AndroidProvider.debug : AndroidProvider.playIntegrity, ); I expect not to see the reCaptch page when calling firebaseAuth.verifyPhoneNumber(...)but I still see the reCaptcha screen. What am I missing? followed every instruction in the documents.

Pubspec: `name: XXX description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 0.1.0+1

environment: sdk: '>=2.19.2 <3.0.0'

dependencies: flutter: sdk: flutter

bloc: ^8.1.1 cached_network_image: ^3.2.3 country_calling_code_picker: ^2.0.1 crop_your_image: ^0.7.4 cupertino_icons: ^1.0.5 device_info_plus: ^8.1.0 dio: ^5.0.0 equatable: ^2.0.5 fimber: ^0.6.6 firebase_app_check: ^0.1.1+13 firebase_auth: ^4.2.7 firebase_core: ^2.6.0 firebase_crashlytics: ^3.0.15 firebase_performance: ^0.9.0+14 flutter_bloc: ^8.1.2 flutter_contacts: ^1.1.6 flutter_easyloading: ^3.0.5 flutter_flavor: ^3.1.1 flutter_keyboard_visibility: ^5.4.0 flutter_native_splash: ^2.2.18 flutter_secure_storage: ^8.0.0 flutter_svg: ^2.0.2 get_it: ^7.2.0 go_router: ^6.0.6 google_fonts: ^4.0.3 http_parser: ^4.0.2 image: ^4.0.15 image_picker: ^0.8.6+3 json_annotation: ^4.8.0 just_the_tooltip: ^0.0.12 path_provider: ^2.0.13 permission_handler: ^10.2.0 pinput: ^2.2.31 retrofit: ^4.0.1 get: ^4.6.5 share_plus: ^6.3.1 tap_debouncer: ^2.0.2 url_launcher: ^6.1.10

webview_flutter: ^4.0.5

dev_dependencies: flutter_test: sdk: flutter

build_runner: ^2.3.3 flutter_gen_runner: ^5.2.0 flutter_lints: ^2.0.1 json_serializable: ^6.6.1 retrofit_generator: ^5.0.0

flutter_native_splash: color: '#000000'

image: assets/images/logo_native_splash_4x.png

flutter_gen: output: lib/core/gen

integrations: flutter_svg: true

flutter:

uses-material-design: true

assets: - assets/images/ - assets/icons/ ` Flutter doctor:

[!] Flutter (Channel stable, 3.7.3, on macOS 12.6 21G115 darwin-arm64, locale en-IL) • Flutter version 3.7.3 on channel stable at /Users/lironitzhaki/flutter ! Warning: dart on your path resolves to /usr/local/Cellar/dart/2.19.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/lironitzhaki/flutter. Consider adding /Users/lironitzhaki/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 9944297138 (5 weeks ago), 2023-02-08 15:46:04 -0800 • Engine revision 248290d6d5 • Dart version 2.19.2 • DevTools version 2.20.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/lironitzhaki/Library/Android/sdk • Platform android-33, build-tools 32.1.0-rc1 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14C18 • CocoaPods version 1.11.3

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Connected device (3 available) • SM S908E (mobile) • R5CT3493C5J • android-arm64 • Android 13 (API 33) • macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 110.0.5481.177

[✓] HTTP Host Availability • All required HTTP hosts are available

! Doctor found issues in 1 category.

lironzemingo avatar Mar 13 '23 12:03 lironzemingo

@lironzemingo The default method is captcha so if you are using SMS auth, the captcha will be shown. The play integrity or app_check is not default. Since you already have SHAs already configured, the app will be using this setting and hence the captcha might be showing up.

In order to narrow down this behavior to only firebase_auth and play integrity (app_check), can you trim down this use case without any third party package implementation ? or just try to see if recaptcha is still shown only using barebone sample project ?

darshankawar avatar Mar 13 '23 12:03 darshankawar

@darshankawar thank you for your reply. I've created a project with only these dependencies: firebase_app_check: ^0.1.1+13 firebase_auth: ^4.2.7 firebase_core: ^2.6.0

with the same applicationId and same google-services.json still, when calling firebaseAuth.verifyPhoneNumber(...), reCaptcha page appears. any thoughts?

lironzemingo avatar Mar 13 '23 12:03 lironzemingo

I expect not to see the reCaptch page when calling firebaseAuth.verifyPhoneNumber(...)but I still see the reCaptcha screen.

@lironzemingo Curious to know as why recaptcha should not be shown ? Since you are trying to authenticate the phone number by using SMS, the recaptcha will be shown if I am not wrong.

darshankawar avatar Mar 14 '23 10:03 darshankawar

@darshankawar in any of the apps that use OTP I've never been displayed with this page. maybe they don't use Firebase... anyway, it says in the docs that this can be avoided by using AppCheck, so I expect this to work. or maybe I misunderstood the purpose of AppCheck

lironzemingo avatar Mar 14 '23 11:03 lironzemingo

Can you please link the documentation ?

darshankawar avatar Mar 15 '23 10:03 darshankawar

Also check this issue and underlying comments for further reference:

https://github.com/firebase/flutterfire/issues/10467

https://github.com/firebase/flutterfire/issues/10174#issuecomment-1370623683

darshankawar avatar Mar 15 '23 10:03 darshankawar

@darshankawar If you are from the official team, could you confirm this is a known issue and we should wait until this is fixed? Your response would help us talk to our clients and get going with what we have. We have been spending too much time trying to get rid off the captcha thinking this is a config issue from our side. Thanks a bunch!

abdu292 avatar Mar 18 '23 11:03 abdu292

Can you please link the documentation ?

what I understand from this link is that if I use Play Integrity, it serves as a valid attestation provider, and is supposed to be instead of reCaptcha. am I wrong? does Firebase Auth use both Play Integrity and reCaptcha?

lironzemingo avatar Mar 19 '23 09:03 lironzemingo

Facing the same issue with reCaptcha. Has anyone found any solution to this?

aqsashaikh88 avatar Mar 20 '23 05:03 aqsashaikh88

@darshankawar Any response on this would be greatly appreciated. (Please see my previous comment)

abdu292 avatar Mar 20 '23 10:03 abdu292

Thanks for the update and patience. I am going ahead and labeling this for team's attention and visibility on expected behavior.

/cc @Lyokone

darshankawar avatar Mar 20 '23 11:03 darshankawar

Still facing this issue. Any solution?

vrishank97 avatar Mar 23 '23 06:03 vrishank97

any updates ?

AhmedElKenawy avatar Mar 24 '23 00:03 AhmedElKenawy

I'm also facing this issue.

seungku avatar Mar 25 '23 00:03 seungku

It is my understanding that you shouldn't see a reCaptcha box if you're using firebase app check. As far as I'm aware, it should handle it in the background and send the user an sms code to verify the user. I wonder if there is a bug in the native SDK 🤔

I think the first port of call is figuring out whether this has recently started happening. Can anyone confirm is this due to a version change? (i.e. it was working, and now it isn't because you upgraded dependency versions).

russellwheatley avatar Apr 04 '23 14:04 russellwheatley

Same issue...

repo-jayptl avatar Apr 04 '23 20:04 repo-jayptl

Thanks for reporting this issue. I believe that there are potentially a few instances where the fallback to reCAPTCHA could occur:

  1. The wrong version of firebase_auth is used. firebase_auth version 4.4.0 is the first version to support Play Integrity API for SMS verification.
  2. You only have a SHA-1 certificate fingerprint registered in the Firebase console. You will need to have the SHA-256 fingerprint certificate registered.
  3. You have the wrong certificate registered. You may have accidentally used your upload certificate rather than the Google Play Signing certificate. You can validate that the Google Play Signing certificate is registered by visiting the Google Play Console, selecting your application, and then in the right hand bar, under Setup, selecting App Integrity. Then in the main window, select App signing and validate that your App signing key certificate (SHA-256 and SHA-1) are registered in the Firebase console. You can also use Peter’s Asset Link Tool to validate that the app deployed on your device is using the right fingerprint as well. This video, while a little outdated and targeted for a web audience, can help you find where in the console to grab your SHA-256 fingerprint.
  4. You deployed straight to your phone rather than downloaded the app from the Play Store. The app needs to come from the Play Store on a real device for Play Integrity API to be used. Otherwise, it may fall back to reCAPTCHA.
  5. You may have exhausted your daily quota of 10,000 API calls per day. If so, you can request a lift on the limit.

A few other notes:

  • As far as I can tell, App Check is not required to be set up on the device. Play Integrity API is baked into the firebase_auth package and no additional client setup is required (other than registering keys, etc..).
  • Off play flows are not supported - you must download the app from Google Play and be running on a real device for this to work.
  • You must register the Google Play Signing Certificate if your app uses Play Signing (unless you were published prior to August 2021 and didn’t upgrade to Play Signing, you likely are using Play Signing).
  • Also, ensure you are running the latest version of Google Play services.

nohe427 avatar Apr 04 '23 22:04 nohe427

Hey @lironzemingo. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Apr 13 '23 01:04 google-oss-bot

Thanks for reporting this issue. I believe that there are potentially a few instances where the fallback to reCAPTCHA could occur:

  1. The wrong version of firebase_auth is used. firebase_auth version 4.4.0 is the first version to support Play Integrity API for SMS verification.
  2. You only have a SHA-1 certificate fingerprint registered in the Firebase console. You will need to have the SHA-256 fingerprint certificate registered.
  3. You have the wrong certificate registered. You may have accidentally used your upload certificate rather than the Google Play Signing certificate. You can validate that the Google Play Signing certificate is registered by visiting the Google Play Console, selecting your application, and then in the right hand bar, under Setup, selecting App Integrity. Then in the main window, select App signing and validate that your App signing key certificate (SHA-256 and SHA-1) are registered in the Firebase console. You can also use Peter’s Asset Link Tool to validate that the app deployed on your device is using the right fingerprint as well. This video, while a little outdated and targeted for a web audience, can help you find where in the console to grab your SHA-256 fingerprint.
  4. You deployed straight to your phone rather than downloaded the app from the Play Store. The app needs to come from the Play Store on a real device for Play Integrity API to be used. Otherwise, it may fall back to reCAPTCHA.
  5. You may have exhausted your daily quota of 10,000 API calls per day. If so, you can request a lift on the limit.

A few other notes:

  • As far as I can tell, App Check is not required to be set up on the device. Play Integrity API is baked into the firebase_auth package and no additional client setup is required (other than registering keys, etc..).
  • Off play flows are not supported - you must download the app from Google Play and be running on a real device for this to work.
  • You must register the Google Play Signing Certificate if your app uses Play Signing (unless you were published prior to August 2021 and didn’t upgrade to Play Signing, you likely are using Play Signing).
  • Also, ensure you are running the latest version of Google Play services.

thanks @nohe427 . my app is only in the early development stage and was not deployed yet in Google Play. so if I understand correctly, what you're saying is that until I sign and upload it to Play, during development I will have to go through reCaptcha with every OTP login. am I right?

lironiz avatar Apr 13 '23 13:04 lironiz

Thanks for reporting this issue. I believe that there are potentially a few instances where the fallback to reCAPTCHA could occur:

  1. The wrong version of firebase_auth is used. firebase_auth version 4.4.0 is the first version to support Play Integrity API for SMS verification.
  2. You only have a SHA-1 certificate fingerprint registered in the Firebase console. You will need to have the SHA-256 fingerprint certificate registered.
  3. You have the wrong certificate registered. You may have accidentally used your upload certificate rather than the Google Play Signing certificate. You can validate that the Google Play Signing certificate is registered by visiting the Google Play Console, selecting your application, and then in the right hand bar, under Setup, selecting App Integrity. Then in the main window, select App signing and validate that your App signing key certificate (SHA-256 and SHA-1) are registered in the Firebase console. You can also use Peter’s Asset Link Tool to validate that the app deployed on your device is using the right fingerprint as well. This video, while a little outdated and targeted for a web audience, can help you find where in the console to grab your SHA-256 fingerprint.
  4. You deployed straight to your phone rather than downloaded the app from the Play Store. The app needs to come from the Play Store on a real device for Play Integrity API to be used. Otherwise, it may fall back to reCAPTCHA.
  5. You may have exhausted your daily quota of 10,000 API calls per day. If so, you can request a lift on the limit.

A few other notes:

  • As far as I can tell, App Check is not required to be set up on the device. Play Integrity API is baked into the firebase_auth package and no additional client setup is required (other than registering keys, etc..).
  • Off play flows are not supported - you must download the app from Google Play and be running on a real device for this to work.
  • You must register the Google Play Signing Certificate if your app uses Play Signing (unless you were published prior to August 2021 and didn’t upgrade to Play Signing, you likely are using Play Signing).
  • Also, ensure you are running the latest version of Google Play services.

thanks @nohe427 . my app is only in the early development stage and was not deployed yet in Google Play. so if I understand correctly, what you're saying is that until I sign and upload it to Play, during development I will have to go through reCaptcha with every OTP login. am I right?

Correct. You will likely need six certificate fingerprints registered with firebase: debug key sha1 and 256, upload key (otherwise known as release key) sha 1 and sha256, and play signing key (sha1 and 256). Play signing uses the sha256 key and the sha1 is used by reCaptcha

nohe427 avatar Apr 13 '23 13:04 nohe427