Question: I set up my app to be able to send Apple Notifications using firebase and I verified that it works using the console. Now I want to do phone authentication which is built on top of APN.

So I wrote this:

```
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { verificationID, error in
  if error != nil {
    print("Verification code not sent \(error!)")
  } else {
    print ("Successful.")
  }

```

And I get:

```
Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x170046db0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
    code = 500;
    message = "<null>";
}}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.}

```

Any idea? Should I file a bug against firebase?

I am using iOS SDK 4.0.0 (latest zip I could find.)

**UPDATE:**

I disabled method swizzling by adding `FirebaseAppDelegateProxyEnabled` to `info.plist` and set it to `NO`

```
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Pass device token to auth.
    Auth.auth().setAPNSToken(deviceToken, type: .prod)
}

```

Answer: 
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)

```
Double check that the app bundle ID in Xcode matches the bundle ID in Firebase **exactly**. And by **exactly**, make sure their case matches - Xcode likes to use mixed case by default for the app name part of the bundle ID.

If you end up changing the bundle ID in Xcode, make sure to manually delete the provisioning profile for the app before generating a new one in Xcode, or it will repeatedly fail (Apple apparently ignores case on profile names).