且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift / Firebase数据库无效令牌错误

更新时间:2023-11-28 09:32:46

这个错误消息表明令牌中的项目与项目不匹配你的应用程序正在连接。读信息范读将亦亦范范读范范范亦读范读亦读范读亦读信息中范读范讯亦范范内预秘范信息


有几种方法可以达到这个目的:


  1. 已将您的GoogleService-Info.plist更改为指向其他项目,但您的应用程序仍然包含上次运行的缓存令牌。

  2. 我相信iOS模拟器共享应用程序之间的钥匙串,所以如果您有多个使用Firebase的应用程序,则一个应用程序可能正在拾取由另一个应用程序缓存的令牌。这个 only 发生在模拟器中,我们正在改变Firebase SDK以避免这种情况。


$ b $信息范读预读亦范亦读范读亦范读程亦中中预54作亦亦亦读范读范范读范范亦范范范范秘范范范范范54上期范信范范范范范范范范范辛范辛范辛范辛范辛范辛范辛范辛范辛辛辛信范范范范范范范范范范范范范范范范范辛范范范范范范范预章辛blockquote>

Experiencing some rather odd issues with Firebase.. I have installed firebase through cocoaPods, included the GoogleService-Info.plist, etc - but when I try to read a value from Firebase, I get this error:

2016-06-16 12:10:04.598 MP[78421:13128189] [FirebaseDatabase] Authentication failed: invalid_token (Invalid claim 'aud' in auth token.)

I have gotten this every single time I have tried to start a new project, except from one time - but I have abandoned that project now, as I am starting a new one. Here is the simple code:

import UIKit
import Firebase
import FirebaseDatabase
class ViewController: UIViewController {
    var ref:FIRDatabaseReference!
    override func viewDidLoad() {
        super.viewDidLoad()
        ref = FIRDatabase.database().reference()
        ref.observeSingleEventOfType(.Value) { (snapshot:FIRDataSnapshot) in
            var val = snapshot.value! as? String
            print(val)
        }
    }
}

How can I fix this?

This error message indicates that the project in the token doesn't match the project that your app is connecting to. From a post on the firebase-talk group:

There are a couple ways you may hit this:

  1. You've changed your GoogleService-Info.plist to point at a different project, but your app still has a cached token from a previous run.

  2. I believe the iOS Simulator shares the keychain between apps, so if you have multiple apps using Firebase, one app might be picking up the token cached by another app. This only happens in the simulator and we're working on changing the Firebase SDK to avoid this.

In either case, you can probably resolve the issue by doing an explicit signOut() call before initializing Firebase Database.