SmsRetrieverHelper SMS verification code request failed: unknown status code: 17499 Error code:39 – Flutter – Firebase Phone Authentication – OTP

huangapple go评论89阅读模式
英文:

SmsRetrieverHelper SMS verification code request failed: unknown status code: 17499 Error code:39 - Flutter - Firebase Phone Authentication - OTP

问题

我正在尝试在这个使用Flutter和Dart的应用程序上启用Firebase电话验证,但每次我输入任何不是测试号码的号码时,都会出现Recaptcha屏幕,然后出现以下错误:

[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Error code:39

另一方面,当我尝试一个测试号码时,一切都很顺利。

这是处理验证过程的AuthController

class AuthController extends GetxController{
  final _auth = FirebaseAuth.instance;
  var verificationId = ''.obs;
  TextEditingController phoneController = TextEditingController();
  var otp = '';
  var _resendToken;

  Future<void> phoneAuthentication(String phone) async{

    await _auth.verifyPhoneNumber(
      phoneNumber: phone,

      verificationCompleted: (credential) {},
      codeSent: (verificationId, resendToken){
        this.verificationId.value = verificationId;
        this._resendToken = resendToken;
        debugPrint('code is sent');
        Get.toNamed(Verification.routeName);
      },
      timeout: const Duration(seconds: 120),
      codeAutoRetrievalTimeout: (verificationId){
        this.verificationId.value = verificationId;
      },
      verificationFailed: (FirebaseAuthException e){
        debugPrint('error message: ${e.message}');
        debugPrint('error code: ${e.code}');
        debugPrint('error stackTrace: ${e.stackTrace}');
        showCustomToast(msg: 'sending failed error code: ${e.code}');
      },
      forceResendingToken: this._resendToken,
    );
  }

  Future<void> verifyOTP(String otp) async{

    try {
      PhoneAuthCredential credential = PhoneAuthProvider.credential(
          verificationId: verificationId.value, smsCode: otp);
      UserCredential user = await _auth.signInWithCredential(credential);
      debugPrint('${credential.smsCode}: credential.smsCode');

      if (user.user != null) {
        Get.offAndToNamed(Home.routeName);
      }
    }
    catch (e){
      showCustomToast(msg: 'wrong code');
    }
  }
}

这是my app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId "com.example.phone_store"
        minSdkVersion 20
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:32.1.0')
    implementation 'com.google.firebase:firebase-auth-ktx'
    implementation 'androidx.browser:browser:1.5.0'
}

configurations.all {
    exclude group: 'com.google.android.gms', module: 'play-services-safetynet'
}

这是android/build.gradle

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

以下是pubspec.yaml中的依赖项:

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0
  otp_text_field: ^1.1.1
  flutter_carousel_slider: ^1.0.8
  intl_phone_number_input: ^0.7.0+2
  cached_network_image: ^3.2.0
  shimmer: ^2.0.0
  flutter_screenutil: ^5.0.1
  firebase_core:
  firebase_auth:
  cloud_firestore:
  flutter_smart_dialog:
  get:

您已将应用程序连接到Firebase的SHA-1SHA-256,确保在Firebase控制台中启用了电话验证,还在Google Cloud中启用了Google Play Integrity API,并确保您的应用程序检查已注册并下载了最新版本的google-service.json,并尝试升级依赖项到最新版本。如果仍然存在问题,请提供更多关于问题的信息,以便我可以为您提供更多帮助。

英文:

I am trying to enable Firebase Phone Authentication on this app using Flutter and Dart
but every time I put any number that is not a test number the Recaptcha screen appears then this error appears:

[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Error code:39

on the other hand, when I try a number that is a test number everything goes well

here is the AuthController that handles the verification process:

class AuthController extends GetxController{
final _auth = FirebaseAuth.instance;
var verificationId = &#39;&#39;.obs;
TextEditingController phoneController = TextEditingController();
var otp = &#39;&#39;;
var _resendToken;
Future&lt;void&gt; phoneAuthentication(String phone) async{
await _auth.verifyPhoneNumber(
phoneNumber: phone,
verificationCompleted: (credential) {},
codeSent: (verificationId, resendToken){
this.verificationId.value = verificationId;
this._resendToken = resendToken;
debugPrint(&#39;code is sent&#39;);
Get.toNamed(Verification.routeName);
},
timeout: const Duration(seconds: 120),
codeAutoRetrievalTimeout: (verificationId){
this.verificationId.value = verificationId;
},
verificationFailed: (FirebaseAuthException e){
debugPrint(&#39;error message: ${e.message}&#39;);
debugPrint(&#39;error code: ${e.code}&#39;);
debugPrint(&#39;error stackTrace: ${e.stackTrace}&#39;);
showCustomToast(msg: &#39;sending failed error code: ${e.code}&#39;);
},
forceResendingToken: this._resendToken,
);
}
Future&lt;void&gt; verifyOTP(String otp) async{
try {
PhoneAuthCredential credential = PhoneAuthProvider.credential(
verificationId: verificationId.value, smsCode: otp);
UserCredential user = await _auth.signInWithCredential(credential);
debugPrint(&#39;${credential.smsCode}: credential.smsCode&#39;);
if (user.user != null) {
Get.offAndToNamed(Home.routeName);
}
}
catch (e){
showCustomToast(msg: &#39;wrong code&#39;);
}
}
}

and this is my app/build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file(&#39;local.properties&#39;)
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader(&#39;UTF-8&#39;) { reader -&gt;
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty(&#39;flutter.sdk&#39;)
if (flutterRoot == null) {
throw new GradleException(&quot;Flutter SDK not found. Define location with flutter.sdk in the local.properties file.&quot;)
}
def flutterVersionCode = localProperties.getProperty(&#39;flutter.versionCode&#39;)
if (flutterVersionCode == null) {
flutterVersionCode = &#39;1&#39;
}
def flutterVersionName = localProperties.getProperty(&#39;flutter.versionName&#39;)
if (flutterVersionName == null) {
flutterVersionName = &#39;1.0&#39;
}
apply plugin: &#39;com.android.application&#39;
apply plugin: &#39;kotlin-android&#39;
apply from: &quot;$flutterRoot/packages/flutter_tools/gradle/flutter.gradle&quot;
apply plugin: &#39;com.google.gms.google-services&#39;
android {
compileSdkVersion 33
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = &#39;1.8&#39;
}
sourceSets {
main.java.srcDirs += &#39;src/main/kotlin&#39;
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId &quot;com.example.phone_store&quot;
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 20
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source &#39;../..&#39;
}
dependencies {
implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version&quot;
implementation platform(&#39;com.google.firebase:firebase-bom:32.1.0&#39;)
implementation &#39;com.google.firebase:firebase-auth-ktx&#39;
implementation &#39;androidx.browser:browser:1.5.0&#39;
}
configurations.all {
exclude group: &#39;com.google.android.gms&#39;, module: &#39;play-services-safetynet&#39;
}

this is my android/build.gradle:

buildscript {
ext.kotlin_version = &#39;1.7.10&#39;
repositories {
google()
mavenCentral()
}
dependencies {
classpath &#39;com.android.tools.build:gradle:7.2.0&#39;
classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version&quot;
classpath &#39;com.google.gms:google-services:4.3.15&#39;
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = &#39;../build&#39;
subprojects {
project.buildDir = &quot;${rootProject.buildDir}/${project.name}&quot;
}
subprojects {
project.evaluationDependsOn(&#39;:app&#39;)
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Here are my depedencies in my pubspec.yaml:

dev_dependencies:
flutter_test:
sdk: flutter
# The &quot;flutter_lints&quot; package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0
otp_text_field: ^1.1.1
flutter_carousel_slider: ^1.0.8
intl_phone_number_input: ^0.7.0+2
cached_network_image: ^3.2.0
shimmer: ^2.0.0
flutter_screenutil: ^5.0.1
firebase_core:
firebase_auth:
cloud_firestore:
flutter_smart_dialog:
get:

I have connected my app with Firebase SHA-1 and also SHA-256, I ensured that the phone authentication is enabled in the Firebase console, I also Enabled Google Play Integrity API in Google Cloud and made sure that my app check is registered and downloaded the latest version of Google.service.json, and I did not forget to try to upgrade my dependencies to the latest version

please help me.

答案1

得分: 1

旧解决方案不再有效。上面提供的链接已不再有效。

主要原因是Google控制台中的某些API不再可用。例如,Android设备验证。

因此,我提供新的解决方案。

如果尚未添加,请添加以下内容。这将帮助您在开发阶段解决一些问题。

Android -> app -> src -> debug -> AndroidManifest.xml

Android -> app -> src -> main -> AndroidManifest.xml

添加到第15行。usesClearTextTraffic;"true"

打开云控制台(cloud.google.com/apis/)并点击左侧面板上的凭据菜单。

点击IOSAndroid编辑API密钥

填写以下区域:

您可以看到SHA-1密钥:

在Mac OS上打开终端并键入以下命令:

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

点击保存

为Android密钥重复相同的过程。

这就是全部,您不应再看到17499错误。

英文:

The old solutions are no longer valid. The links given above are no longer valid.

The main reasons for this are that some APIs in the Google Console are no longer available. For example Android Device Verification.

Therefore, I present the new solution.

Add this if you haven't already. It will help you solve some problems during the development phase.

Android -> app -> src -> debug -> AndroidManifest.xml

Android -> app -> src -> main -> AndroidManifest.xml

add to 15th line. usesClearTextTraffic;"true"

SmsRetrieverHelper SMS verification code request failed: unknown status code: 17499 Error code:39 – Flutter – Firebase Phone Authentication – OTP

Open cloud console (cloud.google.com/apis/) and click Credentials menu on left panel.

SmsRetrieverHelper SMS verification code request failed: unknown status code: 17499 Error code:39 – Flutter – Firebase Phone Authentication – OTP

Click IOS and Android Edit API Key

SmsRetrieverHelper SMS verification code request failed: unknown status code: 17499 Error code:39 – Flutter – Firebase Phone Authentication – OTP

fill this areas:
SmsRetrieverHelper SMS verification code request failed: unknown status code: 17499 Error code:39 – Flutter – Firebase Phone Authentication – OTP

you can see SHA-1 key:
open terminal and write this for mac os

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

Click Save
SmsRetrieverHelper SMS verification code request failed: unknown status code: 17499 Error code:39 – Flutter – Firebase Phone Authentication – OTP

Repeat the same process for Android Key.

That's all, you should no longer see the 17499 error.

huangapple
  • 本文由 发表于 2023年6月2日 10:10:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76386725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定