Firebase client error: Custom token corresponds to a different audience
Embarrassing but true, it turned out to be a simple oversight. When the JS client initialized itself as a Firebase app, before authenticating, it was using old credentials from a test environment.
// Initialize Firebase
var config = {
apiKey: "<WebAPI from Firebase console, 'Project Settings'>",
authDomain: "<myproject>.firebaseapp.com",
databaseURL: "https://<myproject>.firebaseio.com",
projectId: "<myproject>",
storageBucket: "<myproject>.appspot.com",
messagingSenderId: "<id from Console Project Settings>" // optional
};
firebase.initializeApp(config);
The custom token corresponds to a different audience
I finally got the app working, basically firebase does not allow two projects with similar configuration. So in my case the test project I created while development had SHA key of my app configured, becasue of which I was getting the error.
I deleted that key and the conflict got resolved.
This is mainly in cases when you're using modules like Authentication where SHA key is used to identify the app.
Is there a way to sign a Firebase custom token using a service account from a different project
I think the answer is "it is not possible". See statement from a Firebase team member
"A service account can only sign tokens for one and only one project. Any token signed by service account Foo is only valid within the parent project of Foo." -- hiranya911
https://github.com/firebase/firebase-admin-node/issues/634#issuecomment-525953070
Firebase: Create second Custom Token for secondary app
Your admin
variable is initialized with the credentials for your first project. So tokens minted from this admin
instance will only work with that first project.
To create tokens for another project, you'll need to create another FirebaseApp
variable that is initialized with the credentials for that project.
For more on this, also see the Firebase documentation on initializing multiple apps with the Admin SDK, which contains this handy sample:
// Initialize the default app
admin.initializeApp(defaultAppConfig);
// Initialize another app with a different config
var otherApp = admin.initializeApp(otherAppConfig, 'other');
console.log(admin.app().name); // '[DEFAULT]'
console.log(otherApp.name); // 'other'
// Use the shorthand notation to retrieve the default app's services
var defaultAuth = admin.auth();
var defaultDatabase = admin.database();
// Use the otherApp variable to retrieve the other app's services
var otherAuth = otherApp.auth();
var otherDatabase = otherApp.database();
Invalid token because of wrong audience?
I had the same error as you got, but it only occurred in simulator.
To fix this issue I had to reset my simulators content and settings.
Related Topics
Rails - Displaying Foreign Key References in a Form
Model Using Modules in Rails Application
Cucumber + Webrat + Selenium Guide
Sinatra Static Assets Are Not Found When Using Rackup
How to Ignore Multiline Comments in SASS
Get Link and Href Text from HTML Doc with Nokogiri & Ruby
How to Use Basic Authentication with Httparty in a Rails App
Ruby: How to Group a Ruby Array
Rspec Stubbing Method for Only Specific Arguments
How to Get an Empty Temporary Directory in Ruby on Rails
Differencebetween "Rails S" and "Bundle Exec Rails S"
Routing Error - Uninitialized Constant
Retrieve Contents of Url as String
How Does Ruby Serialization (Marshaling) Work
Using Ruby and Net-Ssh, How to Authenticate Using the Key_Data Parameter with Net::Ssh.Start