Firebase: INVALID_TOKEN: Failed to validate MAC - firebase

I get this error when trying to authenticate via Google using custom JWT tokens generated with Flask-restful and firebase-token-generator-python library. In short:
ref.authWithCustomToken(authData)
Error message:
INVALID_TOKEN: Failed to validate MAC.
I am using Angular 2.0.0-beta.2 / Ionic 2. The app is being tested on an android device using cordova-plugin-googleplus (with necessary credentials in Google Developer Console). I have recently enabled Cross-domain requests on nginx server. I can't find any documentation related to this error on Firebase or SO.
Any ideas?

The problem was sending an Authentication Token to Firebase formatted as a JSON string via authData.toString() including delimiters and quotes. This must have thrown the Failed to validate MAC error, whatever that means.

I got the same error when using the incorrect key. I was using the apiKey provided right on the homepage in the Firebase Console while I should have been using the database secret key given at https://console.firebase.google.com/project/YOUR_PROJECT/settings/database.

Related

Error when trying to get expo notification token (Not valid firebase project ID)

I'm trying to use expo notification service to create push notifications in my app. I followed the setup guide in the official docs: https://docs.expo.dev/push-notifications/push-notifications-setup/
However I'm getting the following error instead of getting the device token:
[Unhandled promise rejection: Error: Fetching the token failed: Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.] at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:106:59 in promiseMethodWrapper at node_modules/expo-modules-core/build/NativeModulesProxy.native.js:15:45 in moduleName.methodInfo.name at node_modules/expo-notifications/build/getDevicePushTokenAsync.js:15:69 in getDevicePushTokenAsync at node_modules/expo-notifications/build/getDevicePushTokenAsync.js:4:53 in getDevicePushTokenAsync at node_modules/expo-notifications/build/getExpoPushTokenAsync.js:9:85 in getExpoPushTokenAsync at node_modules/expo-notifications/build/getExpoPushTokenAsync.js:8:51 in getExpoPushTokenAsync
Environment info:
I'm using expo managed workflow. Expo on version 45.0.0.
`
It feels like I should configure my firebase project but I'm still running it on expo go and according to docs, I should only need to do that on build phase. I tried it anyway, but had no success. Also tried reading the provided link on the error and tried to change my firebase init options, but I'm not sure if I did it right.

How to investigate errors in Firebase Remote Config API?

I see errors for the Firebase Remote Config API in the Google Cloud Console > API/Service Details metrics.
Looking at "Traffic by response code" I see that a specific API key is causing HTTP code 400 responses from the API for the method:
google.firebase.remoteconfig.v1.RemoteConfigService.FetchRemoteConfig
I'm not able to reproduce this issue locally so how can I find out more about these errors in the Google Cloud Console?
What I've checked so far:
The credential that is causing the errors is restricted to the correct package name and SHA-1 hash (hash taken from Google Play Console > App Integrity)
It's apparently not hitting a quota limit from looking at the quote graph
From the client side logs I only see the exception:
com.google.firebase.remoteconfig.g: The client had an error while calling the backend!
This is a standard error message used in the Remote Config SDK for a client error (ex: a connection timeout, SSL issue, etc.). I suggest that you double check your implementation. You could also use the Android network debugger to simulate the network calls, so it could create a handling mechanism to ensure that the actual device has a proper connectivity on doing the fetch.
You may also refer to the Stackoverflow post and the GitHub Link.
Google Developer Support pointed me to a known bug in the Firebase Remote Config library which has been fixed recently. Upgrading the library indeed fixed the issue.

Firebase Auth Emulator failing to sign JWT when using Dgraph Authentication

I am trying to find a good way to use the Firebase auth emulator and Dgraph. In Dgraph you send a JWT which contains claims that you can check in Dgraph to allow / limit queries and mutations.
In the Dgraph schema you are required to add the below code:
# Dgraph.Authorization {"Header":"X-Auth-Token","Namespace":"https://dgraph.io/jwt/claims","JWKURL":"https://www.googleapis.com/service_accounts/v1/jwk/securetoken#system.gserviceaccount.com","Audience":["firebase-project-id"]}
I am finding the JWKURL value is invalid when using the firebase auth emulator. It returns this error.
couldn't rewrite query getUser because unable to parse jwt token:token is unverifiable: Keyfunc returned an error
When I try try to use the localhost url Dgraph fails as it can't connect to it.
For example:
localhost:9099/service_accounts/v1/jwk/securetoken#system.gserviceaccount.com
How can I get around this?

Howto call FirebaseAuth.signInWithCustomToken in Java

Using Firebase's Java SDK, I'm able to Create Custom Tokens.
But in order to Verify an ID Token, I first need to signInWithCustomToken using the Web or Android API.
https://firebase.google.com/docs/auth/web/custom-auth
https://firebase.google.com/docs/auth/android/custom-auth
Isn't there away to call signInWithCustomToken while still in the same Java runtime? This source file indicates that there used to be a way to do this. But said function no longer exists in the latest version (com.google.firebase/firebase-admin "6.11.0").
So the first line works in Java. But the second line fails with the given error.
// Works in Java
String token FirebaseAuth.getInstance().createCustomToken("some-uid")
// Fails in Java; only see docs for this, in Android
FirebaseAuth.getInstance().signInWithCustomToken(token)
IllegalArgumentException No matching method found: signInWithCustomToken for class com.google.firebase.auth.FirebaseAuth clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:53)
You can't sign in a user using the Admin SDK on a backend. Signing in can only be done in the client app, which gives it a token to use for the interactions between the app and backend services.

Google Cloud API expired

I am working on a mobile app project with Kotlin and I implemented auth with google. Everything was fine until I recently bought a Firebase license and I restarted the google APIs which throws this error:
com.google.firebase.FirebaseException: An internal error has occurred. [API key expired. Please renew the API key. ].
I tried to generate another key and download the .json file and replace it with the old one. But it's not working.

Resources