Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIS_AUTH_ERROR - when trying to getToken() #5522

Closed
maxembregts1234 opened this issue Jul 16, 2021 · 30 comments
Closed

FIS_AUTH_ERROR - when trying to getToken() #5522

maxembregts1234 opened this issue Jul 16, 2021 · 30 comments
Labels
help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report

Comments

@maxembregts1234
Copy link

maxembregts1234 commented Jul 16, 2021

Hi,

So the problem im having is that when i do the getToken() call on android i get this error in my google developer tools:

[messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: FIS_AUTH_ERROR

and this error in android studio logcat:

E/FirebaseMessaging: Failed to get FIS auth token
java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.

The steps i have taken to setup my android project in firebase:

  • Added the sha-1 key to the android app in firebase console.
  • In the Google Cloud Platform console I have my android api key without restrictions and added the sha-1 key.
  • The google-services.json is in my android/app folder.
  • Added apply plugin: 'com.google.gms.google-services' to android/app/build.gradle.
  • Added classpath 'com.google.gms:google-services:4.3.8' to android/build.gradle

I have tried with and without the SHA-1 key, no difference.
I have tried with and without restrictions, no difference. With restrictions i added these api's:

Cloud Messaging
FCM Registration API
Firebase Cloud Messaging API
Firebase Installations API

Im using the current google-services.json that firebase console gives me when i download it.

I also tried to do a curl command. The curl command gave PERMISSION_DENIED back when i had restrictions on (only those 4 mentioned api's above). The curl command gave this response without restrictions:

curl -H "content-type: application/json" -d "{appId: 'appId', sdkVersion: 't:1'}" https://firebaseinstallations.googleapis.com/v1/projects/project-name/installations/?key=key
{
  "name": "projects/id/installations/dQ8fVUnRxVhSnBNoDs2jLw",
  "fid": "dQ8fVUnRxVhSnBNoDs2jLw",
  "refreshToken": "2_wkBefPcXZ3J32ot1tb8GW1Jl5iCMnaJ4Tuae7-F1eT_8vAyY3cFXwZ-wgWvzUW44",
  "authToken": {
    "token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6IjE6OTYwMzcxMDQxNzc5OmFuZHJvaWQ6MTYxM2FhOWQyZGY1M2Q0MmJkZGU4NiIsImV4cCI6MTYyNjk2NzE0NCwiZmlkIjoiZFE4ZlZVblJ4VmhTbkJOb0RzMmpMdyIsInByb2plY3ROdW1iZXIiOjk2MDM3MTA0MTc3OX0.AB2LPV8wRAIgc_DF2HThEiUZCjEm9eUWz1kcqzj0OU3cCM7akX3JElsCIDDqndwo8r7FU8Vrs1g_QoXowwcisoh2LAKB0GYY7DwQ",
    "expiresIn": "604800s"
  }
}

package.json:

 "@react-native-firebase/app": "^12.1.0",
 "@react-native-firebase/messaging": "^12.1.0",
 "react": "17.0.1",
 "react-native": "0.64.2"

On iOS everything is working fine. I have setup numerous projects with firebase messaging and never had this happen so im quite confused about this whole situation.

If anybody knows whats going on, please let me know.

Greetings,
Max Embregts

@maxembregts1234 maxembregts1234 added help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report labels Jul 16, 2021
@snkhan120
Copy link

snkhan120 commented Jul 16, 2021

I got the same issue;

package.json versions:

"@react-native-firebase/app": "^12.1.0",
"@react-native-firebase/messaging": "^12.1.0",
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-push-notification": "^7.4.0"

Code I tried in App.js

 useEffect(() => {
    (async function () {
      try {
        const token = await messaging().getToken();
        console.log('we have a token and should do something with it: ' + token);

        let tokenRefreshListenerUnsubscriber = messaging().onTokenRefresh(token => {
          console.log('we have a refreshed token and should do something with it: ' + token);
        });
      } catch (e) {
        console.error('token registration failed?', e);
      }
    })();
  }, []);

Log Snapshot:

image

Best,
Ahsan Khan

@snkhan120
Copy link

snkhan120 commented Jul 16, 2021

Problem has been solved, steps need to do,

First check the react-native-push-notification is configured correctly
Second create new firebase project and add android app, download the google-services.json from newly created project app.

then run the code with
./gradlew clean
yarn android

works perfect and get the token

index.js

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

import PushNotification from "react-native-push-notification";

PushNotification.configure({
  onNotification: function (notification) {
      console.log("NOTIFICATION:", notification);
  },
  requestPermissions: Platform.OS === 'ios'
});

AppRegistry.registerComponent(appName, () => App);

App.js

import React, {useEffect} from 'react';
import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,
} from 'react-native';

import {
  Colors,
} from 'react-native/Libraries/NewAppScreen';
import messaging from '@react-native-firebase/messaging';
import PushNotification, {Importance} from 'react-native-push-notification';


const App = () => {

  const createDefaultChannels = () => {
    PushNotification.createChannel(
      {
        channelId: "default-channel-id", // (required)
        channelName: `Default channel`, // (required)
        channelDescription: "A default channel", // (optional) default: undefined.
        soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
        importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
        vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
      },
      (created) => console.log(`createChannel 'default-channel-id' returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
    );
    PushNotification.createChannel(
      {
        channelId: "sound-channel-id", // (required)
        channelName: `Sound channel`, // (required)
        channelDescription: "A sound channel", // (optional) default: undefined.
        soundName: "sample.mp3", // (optional) See `soundName` parameter of `localNotification` function
        importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
        vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
      },
      (created) => console.log(`createChannel 'sound-channel-id' returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
    );

    PushNotification.localNotification({
      /* Android Only Properties */
      channelId: "sound-channel-id", // (required) channelId, if the channel doesn't exist, notification will not trigger.
    
      actions: ["Yes", "No"], // (Android only) See the doc for notification actions to know more
      invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true
    
      title: "My Notification Title", // (optional)
      message: "My Notification Message", // (required)
    });

  }

  

  const checkToken = async () => {
    const fcmToken = await messaging().getToken();
    if (fcmToken) {
       console.log(fcmToken);
    } 
   }
   
  //  checkToken();

  async function requestUserPermission() {
    const authStatus = await messaging().requestPermission();
    const enabled =
      authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
      authStatus === messaging.AuthorizationStatus.PROVISIONAL;
  
    if (enabled) {
      console.log('Authorization status:', authStatus);
    }
  }

  useEffect(() => {
    // createDefaultChannels();
   checkToken();

  }, []);

  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <View
          style={{
            backgroundColor: isDarkMode ? Colors.black : Colors.white,
          }}>
          <Text>Hello, world!</Text>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
  },
  highlight: {
    fontWeight: '700',
  },
});

export default App;

Best,
Ahsan Khan

@maxembregts1234
Copy link
Author

maxembregts1234 commented Jul 16, 2021

I don't use react-native-push-notification. I created a new firebase project, added android app, downloaded google-services.json. Still same error.

export const checkPermission = () => {
  messaging().hasPermission().then((enabled) => {
    if (enabled) {
      getToken();
    } else {
      requestPermission();
    }
  }).catch((error) => {
    console.log('Error checking permissions ' + error);
  });
};

const requestPermission = () => {
  messaging().requestPermission().then(() => {
    getToken();
  }).catch((error) => {
    console.log('Permission rejected ' + error);
  });
};

const getToken = () => {
  messaging().getToken().then((token) => {
    console.log(token);
  }).catch((error) => {
    console.log('Error getting push token ' + error);
  });
};

@mikehardy
Copy link
Collaborator

Not sure what is going on, but it is definitely centered around your API key. Something is not what it appears to be with regard to the key actually in use by the app, and how it is configured.

This seemed like a reasonable explanation of the above to consult https://stackoverflow.com/questions/61453640/android-error-when-communicating-with-the-firebase-installations-server-api/61529757#61529757 - you indicate you've set up a few apps before so it's likely unexpected and you've been through this, yet still there is something wrong in exactly this API key area around Firebase Installations

@maxembregts1234
Copy link
Author

@mikehardy I did what that post did. I also tried to make a new firebase project with a new android app. I tried to delete the whole app from device and remove all the build folders. Nothing is working, I just don't get it :(

@maxembregts1234
Copy link
Author

maxembregts1234 commented Jul 21, 2021

Anybody else got any other ideas about what the problem could be. I have checked my API key so many times already. The API key in the google-services.json is the same as in the google cloud platform.

@timothyerwin
Copy link

I'm getting the same problem...not sure what is up

@timothyerwin
Copy link

timothyerwin commented Jul 21, 2021

It looks like I fixed it by downgrading the minor version...not sure what they changed.

"@react-native-firebase/app": "^12.0.0",
"@react-native-firebase/messaging": "^12.0.0",

@mikehardy
Copy link
Collaborator

mikehardy commented Jul 21, 2021

That's really unexpected. I wonder if this would be resolved by downloading a new set of google-services json/plist files? (this was required for a similar error when firebase underlying SDKs were bumped - it would be an unexpected side effect of the SDK bump in that case and I'll have to think about updating the changelog...)

@maxembregts1234
Copy link
Author

Downgraded versions to 12.0.0 and redownloaded config, same problem.

@timothyerwin
Copy link

timothyerwin commented Jul 22, 2021 via email

@maxembregts1234
Copy link
Author

Yes, its reinstalled with npm. Version 12.0.0 for both.

@maxembregts1234
Copy link
Author

maxembregts1234 commented Jul 22, 2021

After days of trying to find a solution and frustration, I finally found a solution to my problem. In my app im using ssl pinning and apparently that was causing the issue. I found this post on stackoverflow:

https://stackoverflow.com/questions/60698622/java-io-ioexception-fis-auth-error-in-android-firebase

In this post if you scroll down enough you will find this:

"Hope this helps someone:

In my situation, I used self-signed ca. So I need to use network-security-config.xml

After huge try and error, finally I add system directory in trust-anchors like below, FIS_AUTH_ERROR is gone and Firebase worked."

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config>
        <trust-anchors>
            <certificates src="system" />  <!-- for Firebase -->
            <certificates src="user" /> <!-- for tooling.   Ex:Charles --> 
            <certificates src="@raw/ca_1"/> <!-- my self-signed ca-->
        </trust-anchors>
    </base-config>
</network-security-config>

This file is found in: android/app/src/main/res/xml/network-security-config.xml

This basically fixed my problem. Finally.

Thanks for all the other responses and help though.

@timothyerwin
Copy link

@mikehardy well I just created a new firebase project with the latest downloads so maybe check against that.

@mikehardy
Copy link
Collaborator

@timothyerwin I'm not sure how that is relevant. I'm not having this issue, just 3 hours ago someone reported success (after unrestricting security chain a bit...) with current versions.

To me that means: react-native-firebase + firebase is working. Your project and/or API key and/or SSL config is not working. That's not an issue I here I don't think?

@timothyerwin
Copy link

@mikehardy I'm just responding to your earlier comment:

That's really unexpected. I wonder if this would be resolved by downloading a new set of google-services json/plist files?

I'm not sure why you want to paint this as a me problem when I'm clearly not the only one having this. If I downgrade a minor version and things suddenly work how is it a me problem now? lol...yes, other people have solved this after tinkering around with things and mentioning "days of frustration"...but I guess everyone else is the issue... :)

@mikehardy
Copy link
Collaborator

There are lots of reasons it can happen, for every person that has had it, it is a "me" problem yes. Based on the fact it is possible for it to work, it is not a module problem. As a maintainer, with apologies, that is my vital interest --> I must fix bugs in the module. With whatever time I have left over I can try to offer help, but if it's not a module bug it's project issue, it's a bit binary in that way

@timothyerwin

This comment has been minimized.

@mikehardy

This comment has been minimized.

@timothyerwin

This comment has been minimized.

@mikehardy
Copy link
Collaborator

Hey @timothyerwin I mean this sincerely: I would welcome any documentation PR that sums up whatever specific project-specific items may need attention based on whatever evidence is posted here. We have a tips and tricks section for this purpose, and there's an edit button on the top right https://rnfirebase.io/faqs-and-tips - the project's not perfect and the documentation is largely improved by users, in this specific area the project is working though. Yet users are still having issues for what appears to be a wide variety of reasons. Any help untangling that could save future devs a lot of time, and that would be a plus

@SimajjiHans
Copy link

I also had this issue, I solved this by manually removing the current_key under api_key object on google-services.json.

Apparently Google put other Firebase app API key as well and those keys are restricted (while my test project key is not).

Hope this helps future devs some time

@mashish584
Copy link

mashish584 commented Mar 10, 2022

I was switching a project from v5 to v14 in an App & caught this issue while generating token.

What I've missed to add while migrating is

implementation platform('com.google.firebase:firebase-bom:xx.x.x')

Token is generated successfully after adding this line.

@mikehardy
Copy link
Collaborator

@mashish584 something is wrong - that should not be necessary, we do that for you right here:

implementation platform("com.google.firebase:firebase-bom:${ReactNative.ext.getVersion("firebase", "bom")}")

@mashish584
Copy link

@mikehardy Bit strange for me as well because in other projects it's working fine without adding "firebase-bom". I'll try to inspect it on my end once I got some time.

@taylorkline
Copy link

taylorkline commented Apr 26, 2022

@maxembregts thank you SO much. Ran into this same issue because of SSL pinning. You saved me hours of (more) digging.

@mzupek
Copy link

mzupek commented Jan 6, 2023

I also had this issue, I solved this by manually removing the current_key under api_key object on google-services.json.

Apparently Google put other Firebase app API key as well and those keys are restricted (while my test project key is not).

Hope this helps future devs some time

This solution worked for me, not sure how the API key got replaced

@spsaucier
Copy link

spsaucier commented Apr 4, 2023

The fix for me was to update the API key to include these two permissions:

Firebase Cloud Messaging API
Firebase Installations API

@Orest1996
Copy link

in my case problem was wrong google-services.json file (was copied from other prjoect before) after I changed it by correct one from firebase console, everything started working

@chanphiromsok
Copy link

in my case problem was wrong google-services.json file (was copied from other prjoect before) after I changed it by correct one from firebase console, everything started working

after solved my issue and I found your it's correct

  • google-service.json is changed so just download goggle-service.json and rebuild your app it is work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report
Projects
None yet
Development

No branches or pull requests