AppCheckProtocolAPITests.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2024 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // MARK: This file is used to evaluate the AppCheckProtocol API in Swift.
  15. import Foundation
  16. // MARK: Do not import `FirebaseAppCheck`, this file is for `FirebaseAppCheckInterop` only.
  17. import FirebaseAppCheckInterop
  18. final class AppCheckProtocolAPITests {
  19. let appCheck: AppCheckProtocol! = nil
  20. func usage() {
  21. let _: Void = appCheck.token(forcingRefresh: false, completion: { token, error in
  22. if let token: AppCheckTokenProtocol {
  23. let _: String = token.token
  24. let _: Date = token.expirationDate
  25. }
  26. if let error: Error {
  27. let _: String = error.localizedDescription
  28. }
  29. })
  30. let _: Void = appCheck.limitedUseToken { token, error in
  31. if let token: AppCheckTokenProtocol {
  32. let _: String = token.token
  33. let _: Date = token.expirationDate
  34. }
  35. if let error: Error {
  36. let _: String = error.localizedDescription
  37. }
  38. }
  39. }
  40. @available(iOS 13, macOS 10.15, macCatalyst 13, tvOS 13, *)
  41. func usage_async() async {
  42. do {
  43. let token: AppCheckTokenProtocol = try await appCheck.token(forcingRefresh: false)
  44. let _: String = token.token
  45. let _: Date = token.expirationDate
  46. } catch {
  47. let _: String = error.localizedDescription
  48. }
  49. }
  50. }