like this SO Question
我的复杂之处在于使用Firebase API获取承载令牌,因为它有一个完成处理程序在承载令牌过期的情况下,刷新令牌用于尝试获取新的承载令牌:
static func getIdToken(completion: @escaping (String?, Error?) -> Swift.Void) {
guard let user = Auth.auth().currentUser else {
print("No Firebase User!")
completion(nil, nil)
return
}
user.getIDToken { (idToken, error) in
if(error != nil ) {
print("AuthUtiltiy, error retrieving token: \(error!.localizedDescription)")
completion(nil, error)
return
}
completion(idToken, nil);
}
}
private var manager = Alamofire.SessionManager.default
// Setups the cookie and shared instance
override init() {
let defaultHeaders = manager.session.configuration.httpAdditionalHeaders ?? [:]
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = defaultHeaders
manager = Alamofire.SessionManager(configuration: configuration)
}
RequestAdapter
,
introduced in AlamoFire 4.0
又是因为同样的原因Firebase.getIdToken回调/完成处理程序。