J.Doe
J.Doe

Reputation: 397

Invalid token because of wrong audience?

I just made a firebase project, installed the pods and got the googleplist in, configured it in the app delegate, and set it up exactly like I have other projects.

For my pods, I've got exactly what I have in my main other project :

pod 'Firebase/Core’
pod ‘Firebase/Auth’
pod ‘Firebase/Database’

When I run this code :

let ref = FIRDatabase.database().reference()

ref.setValue("hello")

I get an error that pops up like 50 times that says :

MyProjectName[209384092:9028304928034randomnumbers] [FirebaseDatabase] Autentication failed: Invalid_token (audience was project 'a random project from my firebase console' but should have been project 'myProjectName'.

I thought maybe I had done something really goofy at first, so I deleted my project entirely and reinstalled a new google.plist and redid everything, but the only thing that has changed is now I'm just getting a different random project from my firebase project list.

What's goin' on here?

Upvotes: 3

Views: 2071

Answers (3)

Manuel Bautista
Manuel Bautista

Reputation: 138

Maybe you are not taking the correct apiKey and authDomain. Go to Firebase, select the project go to Authentication and then Web Setup and see if the apiKey and authDomain are the same keys that you are using in the firebase.initializeApp({});

Upvotes: 0

dead_can_dance
dead_can_dance

Reputation: 129

If anyone is experiencing this issue on an actual iPhone device rather than the simulator the root cause of this issue is provided in another SO thread:

Swift/Firebase Database invalid token error

It looks Firebase plan to address it in a future SDK update but to resolve it for now you must sign-out + invalidate your Firebase Database session in your 'old' project first:

NSError *error;
[[FIRAuth auth] signOut:&error];
if (error) {
    ELog(@"Firebase Logout failed: %@", error.localizedDescription);
}

Your 'new' project should then now function as expected.

Upvotes: 1

Ivan Le Hjelmeland
Ivan Le Hjelmeland

Reputation: 1065

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.

simulator - reset content and settings...

Upvotes: 3

Related Questions