英文:
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-1和SHA-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 = ''.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');
}
}
}
and this is 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 {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.phone_store"
// 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 '../..'
}
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'
}
this is my 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
}
Here are my depedencies in my pubspec.yaml:
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" 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/)并点击左侧面板上的凭据菜单。
点击IOS和Android编辑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"
Open cloud console (cloud.google.com/apis/) and click Credentials menu on left panel.
Click IOS and Android Edit API Key
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
Repeat the same process for Android Key.
That's all, you should no longer see the 17499 error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论