AppCheckTests.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2020 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import XCTest
  17. import FirebaseCore
  18. import FirebaseAppCheck
  19. class AppCheckTests: XCTestCase {
  20. func usageExample() {
  21. AppCheck.setAppCheckProviderFactory(self)
  22. FirebaseApp.configure()
  23. let firebaseOptions = FirebaseOptions(contentsOfFile: "path")!
  24. FirebaseApp.configure(name: "AppName", options: firebaseOptions)
  25. AppCheck.appCheck().token(forcingRefresh: true) { token, error in
  26. // ...
  27. }
  28. }
  29. #if swift(>=5.5)
  30. func asyncGetTokenUsageExample() async throws {
  31. _ = try await AppCheck.appCheck().token(forcingRefresh: true)
  32. }
  33. #endif // swift(>=5.5)
  34. }
  35. class DummyAppCheckProvider: NSObject, AppCheckProvider {
  36. func getToken(completion handler: @escaping (AppCheckToken?, Error?) -> Void) {
  37. handler(AppCheckToken(token: "token", expirationDate: .distantFuture), nil)
  38. }
  39. }
  40. extension AppCheckTests: AppCheckProviderFactory {
  41. func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
  42. return DummyAppCheckProvider()
  43. }
  44. }