简体   繁体   English

尝试使用 firebase 验证电话号码时出现“无效令牌”

[英]"Invalid Token" when trying to authenticate phone number using firebase

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域 = FIRAuthErrorDomain 代码 = 17048“无效令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域=FIRAuthErrorDomain 代码=17048“无效的令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域=FIRAuthErrorDomain 代码=17048“无效的令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域=FIRAuthErrorDomain 代码=17048“无效的令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域=FIRAuthErrorDomain 代码=17048“无效的令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域=FIRAuthErrorDomain 代码=17048“无效的令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域=FIRAuthErrorDomain 代码=17048“无效的令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

could you please try generating a new APNs key and upload it to your Firebase project. 您能否尝试生成一个新的APNs密钥并将其上传到Firebase项目。 (go Project Settings -> Cloud Messaging -> iOS app configuration). (转到项目设置->云消息传递-> iOS应用配置)。 Or use an APNs Certificate instead. 或改为使用APNs证书。 Please let me know if it works for you. 请让我知道它是否适合您。

This is my code:这是我的代码:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in
            if let error = error {
                print(error)
                return
            }
            UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
        }
    }

    static func verify(verificationCode: String?) {
        guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }
        if verificationCode != nil {
            let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationID,
                verificationCode: verificationCode!)

            Auth.auth().signIn(with: credential) { (user, error) in
                if let error = error {
                    print(error)
                    return
                }
            }
        } else {
            print("No verification code")
        }
    }

}

This is what the console prints out:这是控制台打印出来的:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token."错误域=FIRAuthErrorDomain 代码=17048“无效的令牌。” UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL} UserInfo={NSLocalizedDescription=无效令牌。,error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong?我究竟做错了什么? Thanks谢谢

If you have tried adding the APNs key (p8) in your Firebase console and also checked for the Correct bundle Id and Correct Google-Info.plist.如果您尝试在 Firebase 控制台中添加 APNs 密钥 (p8) 并检查了正确的捆绑包 ID 和正确的 Google-Info.plist。 And still the issue persists Do check if you have "Push Notifications" enabled and "Remote notifications" selected in "Signing and capabilities" in Xcode->Runner but are not actually using firebase messaging Then care to uncheck "Remote notifications" from "Signing and capabilities" and remove "Push Notifications" in Xcode->Runner.问题仍然存在 请检查您是否启用了“推送通知”并在 Xcode->Runner 的“签名和功能”中选择了“远程通知”,但实际上并未使用 firebase 消息传递然后注意取消选中“签名”中的“远程通知”和功能”并删除 Xcode->Runner 中的“推送通知”。 In my case this was the issue就我而言,这是问题所在

I faced same problem when I want send OTP and get notifications, I created APN key on apple developer console then added it to firebase after that everything got well:当我想发送 OTP 并获取通知时,我遇到了同样的问题,我在苹果开发者控制台上创建了 APN 密钥,然后将其添加到 firebase 之后一切顺利: 在此处输入图像描述

I want to back my account.我想备份我的帐户。 I can not varify my account with gimel account .我无法使用 gimel account 更改我的帐户。 There are no any varification message to sent for me.没有任何更改消息要发送给我。 So, please anyone help to back my account .所以,请任何人帮助支持我的帐户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在 firebase 中使用 google 对用户进行身份验证时出错 - Error when trying to authenticate users with google in firebase flutter 中的 firebase_auth/无效电话号码? - firebase_auth/invalid-phone-number in flutter? 如何使用 flutter 检查电话号码是否已在 firebase 身份验证中注册 - How to check if phone number is already registered in firebase authentication using flutter Swift/Firebase 数据库无效令牌错误 - Swift/Firebase Database invalid token error Firebase 身份验证 iOS 12 无效令牌 - Firebase Authentication iOS 12 invalid token Unity/Firebase 如何使用 Google 进行身份验证? - Unity/Firebase How to authenticate using Google? 通过 firebase 注册用户并收集他的名字、姓氏、电话号码和地址时是否有可能? - Is it possible when registering a user via firebase and react to collect his first name, last name, phone number and address? iOS 应用程序在尝试使用 Firebase 身份验证“使用 Apple 登录”时崩溃 - iOS app crashes when trying to "Sign in with Apple" using Firebase Authentication Firebase 身份验证 - 无法添加电话号码进行测试 - Firebase Auth - Unable to Add Phone Number for Testing 具有真实电话号码的 Firebase PhoneAuth 无法使用,但白名单号码可以使用 - Android - Firebase PhoneAuth with Real phone Number Is Not Working But Whitelisted Number is Working - Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM