“Invalid Token” when trying to authenticate phone number using firebase

前端 未结 7 1985
庸人自扰
庸人自扰 2020-12-16 11:13

This is my code:

import FirebaseAuth


class AuthPhoneNum {

    static func getPhoneNum(phoneNumber: String) {
        PhoneAuthProvider.provider().verifyPh         


        
相关标签:
7条回答
  • 2020-12-16 11:48

    In my case, the problem was an incorrect bundle id in the iOS app, in the firebase project settings (Project settings -> General -> Your apps).

    I hope this helps anyone overlooking the same detail.

    0 讨论(0)
  • 2020-12-16 11:49

    Make sure that it is APNs that you are selected under Key Services. The number of APNs certificates per developer account is limited to 2. So if you already had 2 certificates before, there is a chance that you are created the certificate by checking DeviceCheck instead of APNs.

    0 讨论(0)
  • 2020-12-16 11:50

    First regenerates APNS key and upload in firebase for cloud messaging

    1) Import Firebase and FirebaseAuth

    import Firebase
    import FirebaseAuth
    

    2) In didFinishLaunchingWithOptions Configure firebase.

    FirebaseApp.configure()
    

    3) Write these two func in AppDelegate.

      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let firebaseAuth = Auth.auth()
        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
    
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let firebaseAuth = Auth.auth()
        if (firebaseAuth.canHandleNotification(userInfo)){
            print(userInfo)
            return
        }
    }
    

    Very Important note : uthAPNSTokenType set correctly for [sandbox / production] or set for common .unknown

    In my case it was the apns token type that was wrong:

    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
    

    should have been:

    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
    
    0 讨论(0)
  • 2020-12-16 11:50

    For any one else who double checked the above and still have issues, don't forget to add your team ID and App Id in your ios config file.

    And, don't forget to download it again, and replace your old one with the updated one.

    0 讨论(0)
  • 2020-12-16 11:51

    It is most likely that you need to upload an .p8 Key file (I have an Enterprise account but same thing for developer)
    In Apple Developer Account:

    • All Keys
    • Create New Key (+)
    • Type in Global name for all of your apps
    • Checkbox next to Apple Push Notifications service (APNs)
    • Download your p8 file
    • Upload to firebase dashboard
    0 讨论(0)
  • 2020-12-16 11:53

    same problem questions have been before on SO. so would like to tell you setup all pre-require step before run code.

    Pre-Require Steps:

    • Register bundle id on Developer account and enable notifications for bundle id.

    • Register same bundle id on firebase console setting page and create app, download Google-Info.plist file, make sure name should be same.

    • Upload Push certificates on firebase console for sandbox as well as development.

    • follow this below link for code implementation.

    setup code for Firebase Auth

    0 讨论(0)
提交回复
热议问题