Firebase Phone Authentication Error: Invalid Token (Even after replacing APNs Key) - ios

Today may production app started having issues on Phone Authentication through Firebase on several devices (but not all).
When I make the call PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber: uiDelegate:) I get the following error:
Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token." UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL
As per Firebase documentation, this code indicates that an invalid APNS device token was used in the verifyClient request.
Nothing in my app code has changed, yet this error is occurring. I uploaded a new APNs Key and .p8 file as other StackOverflow posts have suggested, with no luck.
I have tried the suggestions in this similar post.
I am also able to receive push notifications from my app to this device, so it isn't like my push notifications aren't working.
Could anyone suggest ways of debugging his?
Edit: This is the method I am calling:
func sendVerificationCode(to phoneNumber: String, _ completion: #escaping (Error?)->Void) {
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in
/* store verificationID locally if exists */
completion(error)
}
}

firebaser here
There was an issue where iOS clients were not receiving the text messages required for one-time password authentication. Its status is being tracked here: https://status.firebase.google.com/incident/Authentication/18006
From there:
We are investigating an issue with Firebase Phone authentication that affects iOS devices. Affected customers may see "invalid token" error during OTP verification.
This issue has been fixed, since 11:15 am pacific time. If you're still seeing similar problems, reach out to Firebase support for personalized help in troubleshooting.

Related

Do I need APNs certificates if I'm using APNs Auth Key?

I'm writing an cross-platform app with Flutter and Firebase. I've been working on sending notifications, and it works perfectly on android. I send messages via the firebase admin functions sdk with no problems. The request looks like this:
const payload = {
notification: {
title: title,
body: body,
},
}
return admin.messaging().sendToDevice(tokens, payload, {
mutableContent: true,
contentAvailable: true,
apnsPushType: "background",
})
But when I try to send messages to iOS devices, I get the following error from the shell:
"error": {
"errorInfo": {
"code": "messaging/third-party-auth-error",
"message": "A message targeted to an iOS device could not be sent
the required APNs SSL certificate was not uploaded or
has expired. Check the validity of your development and
production certificates."
},
"codePrefix": "messaging"
}
I was under the impression that since I'm using a APNs key generated in the apple developer console, that I would not need any sort of SSL certificate. My key is uploaded to the Firebase console and iOS devices are successfully reporting their device tokens, so I'm not sure why I can't get a message through.
I've tried sending messages from the CLI and also from the FCM console online. Both have failed.
I've also enabled Push Notifications and Background Modes with background fetch and remote notifications.
Any help or suggestions would be appreciated.
This is really stupid, but the issue was an incorrect Bundle ID in firebase. When I first hooked up firebase it gave me a default bundle id (com.firebase.io or something dumb like that). Later when I actually put my app on testflight i called it something else entirely. So even though I followed all the directions on the FlutterFire website for setting up apple here it didn't work bc the bundle ids didn't match.
So I had to delete the firebase app, replace the googleservicesinfo.plist file (thought it might have been sufficient to just change the bundle id field in that file (idk for sure tho)) and then replaced it in the firbase console. Had to reupload the auth key too with the "new" app.
Hope that makes sense. Comment if you have any other questions!

HealthKit requestAuthorization returns code 100: "Authorization session timed out"

All of my HealthKit authorization requests are timing out with this error. Nothing in my code has changed, but I recently switched Xcode over to a new Apple ID account.
I have a development team setup, a provisioning profile configured, and the HealthKit Capability and Entitlement working. My app builds and runs fine, but any time I make a requestAuthorization call, I get a timeout for no apparent reason. There's no additional information in the error, and everything appears to be configured properly, so I'm pretty lost on what could cause this.
I've tried both simulators and devices with the same issue. The dialog for HealthKit auth never appears. I can go into the Health app after the fact and turn on the necessary data sharing, but this is a not an acceptable workaround.
What can cause healthKitStore requestAuthorization timeout errors?
I am 99% sure this is a configuration issue, but having gone through the process multiple times, and re-created numerous certs, provisioning profiles etc, I don't know what the problem could be. Where should I be looking for config issues? There is essentially zero documentation on this, and I've only found 2 results on Google related to this with no solutions.
let healthKitTypesToRead = [...]
let healthKitStore:HKHealthStore = HKHealthStore()
healthKitStore.requestAuthorization(toShare: nil, read: healthKitTypesToRead) { (success, error) -> Void in
if( completion != nil ) {
completion(success, error as? NSError)
}
}
This was due to running the authorization request in a background thread. Doing it on the main thread solved the problem.

LinkedIn sdk iOS error if already logged in to LinkedIn App

I'm using the iOS LinkedIn SDK to log into my App and retrieve basic profiles.
All works perfectly fine the first time I login, until either I log out, or I close my App.
On attempting to log back into my App with LinkedIn: the usual redirect to the LinkedIn app takes place, but the permissions screen for my app doesn't pop up, it just redirects straight back to my app with the following error:
Error Domain=LISDKAuthError Code=5 "(null)" UserInfo={errorDescription=The operation couldn’t be completed. Software caused connection abort, originalDomain=LISDKServerError, errorInfo=PARSING_ERROR}
I can only successfully log back in again if I first close the LinkedIn App, before reopening mine.
Does anyone have an idea of what's going on please?
-This doesn't occur on all of my test devices!
-On the device that it does occur on, I also receive the same error in that scenario when running the sample App provided with the LinkedIn SDK.
-The LinkedIn App is up to date.
-The App id, bundle ids etc etc are all set, hence login success half of the time!
-I've tried calling [LISDKSessionManager clearSession] in numerous locations.
Cheeky framework fix alert.
Uncomment out the lines in LISDKSession.h
This allows the correct use of [LISDKSessionManager hasValidSession]
Which is an improvement on what we were working with.
Not yet tested with iOS12...
I had a similar problem. It was mainly reproduced only on iOS 12. The problem is that when you already have a LinkedIn application running, you will not be able to log in through their SDK in your application. On iOS 11, the second time you try to log in after this error, the authorization worked fine.
I solved this issue by simply showing the user an alert with a message about what he needs to do to authorize.
Here you can check an example of my implementation in Swift 4:
LISDKSessionManager.createSession(withAuth: ["r_basicprofile"],
state: nil,
showGoToAppStoreDialog: true,
successBlock: { _ in
// Your actions in case of successful authorization
}, errorBlock: { error in
guard let nsError = error as NSError? else {
return
}
if #available(iOS 12.0, *),
nsError.code == LISDKErrorCode.SERVER_ERROR.rawValue {
// Show alert to user with text - "Please, shut down the LinkedIn app and try login again"
} else if nsError.code != LISDKErrorCode.USER_CANCELLED.rawValue {
// Handling when user tap on Cancel button in LinkedIn SDK
}
})
I've been battling for a fix for this with LinkedIn for months.
There 'solution' is to kill off the SDK.
Taken from their 'Important updates to the LinkedIn Developers program and APIs' email December 2018:
"Authentication, SDKs, and Plugins: We are also deprecating several obsolete or seldomly-used products and technologies."
"SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps."
Uncomment this two lines of code in LISDKSession.h
- (LISDKAccessToken *)getAccessToken;
- (void)setAccessToken:(LISDKAccessToken *)accessToken;

iOS - Runtime errors with GCM

I'm not sure if this is an issue of the library or something wrong on our side but I already spent a lot of time searching about this and found nothing that could shed any light.
We're using GCM since a while on both iOS and Android. The application is in production and is working fine. Our iOS app collects and reports low-impact errors (basically errors we catch and handle) and analyzing these data I found those errors I'm struggling to understand.
While registering a device on GCM with an APNS token
Error Domain=com.google.iid Code=1006 "(null)" that according to the documentation is kGGLInstanceIDOperationErrorCodeInvalidKeyPair
While subscribing to a topic
Error Domain=com.google.gcm Code=501 "(null)" that according to the documentation is kGGLInstanceIDOperationErrorCodeMissingDeviceID
Both errors happens on iOS8/iOS9/iOS10.
Our app includes the GCM library via Cocoapods:
pod 'Google/CloudMessaging', '2.0.4'
Can someone help me understanding what's happening?
Thanks!
The first error kGGLInstanceIDOperationErrorCodeInvalidKeyPair means that you have error in KeyPair access. While the error kGGLInstanceIDOperationErrorCodeMissingDeviceID means that your device seems to be missing a valid deviceID. It cannot authenticate device requests. From this related thread, error code 501 was solved by resetting all data and settings on the device (factory reset) and this fixed the problem. It's also stated here that the error occurred maybe because you are calling GCMService.sharedInstance().connectWithHandler() { error in if(error != nil) { print(error) } } before you had received a registration token, or had failed to refresh your token.
But I found this SO question which have similar issue with you which suggests to transition to Firebase Cloud Messaging as recommended by Google and his issue was solved.

GCM registration successful on iphone but not ipad

I have a weird issue where I receive the following error only on an ipad device:
The operation couldn’t be completed. (com.google.iid error 501.)
During the GCM registration process to request a gcm token. i.e.
GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,
scope: kGGLInstanceIDScopeGCM,
options: gcmRegistrationOptions,
handler: gcmRegistrationHandler)
I'm following the example to the letter. The same process works just fine on an iphone. I'm not sure what the difference between the two devices are and why GCM refuses to register on the ipad. Both devices are currently running iOS 9.3.1.
The header file indicates that this error corresponds to:
// Device seems to be missing a valid deviceID. Cannot
// authenticate device requests.
kGGLInstanceIDOperationErrorCodeMissingDeviceID = 501,
However, I'm not sure exactly what that means. Why would the iPad be missing a deviceID, but the iphone is OK?
If anyone has any ideas on why this is happening and can share some insight, I'd greatly appreciate it.
Thanks!
In the end we transitioned to Firebase as recommended by Google recently. Everything worked as expected.

Resources