FIRAppCheckTokenRefresher.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2021 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 <Foundation/Foundation.h>
  17. #import "FirebaseAppCheck/Sources/Core/TokenRefresh/FIRAppCheckTimer.h"
  18. @protocol FIRAppCheckSettingsProtocol;
  19. @class FIRAppCheckTokenRefreshResult;
  20. NS_ASSUME_NONNULL_BEGIN
  21. /** The block to be called on the token refresh completion.
  22. * @param refreshResult The refresh result.
  23. */
  24. typedef void (^FIRAppCheckTokenRefreshCompletion)(FIRAppCheckTokenRefreshResult *refreshResult);
  25. /** The block that will be called by `FIRAppCheckTokenRefresher` to trigger the token refresh.
  26. * @param completion The block that the client must call when the token refresh was completed.
  27. */
  28. typedef void (^FIRAppCheckTokenRefreshBlock)(FIRAppCheckTokenRefreshCompletion completion);
  29. @protocol FIRAppCheckTokenRefresherProtocol <NSObject>
  30. /// The block to be called when refresh is needed. The client is responsible for actual token
  31. /// refresh in the block.
  32. @property(nonatomic, copy) FIRAppCheckTokenRefreshBlock tokenRefreshHandler;
  33. /// Updates the next refresh date based on the new token expiration date. This method should be
  34. /// called when the token update was initiated not by the refresher.
  35. /// @param refreshResult A result of a refresh attempt.
  36. - (void)updateWithRefreshResult:(FIRAppCheckTokenRefreshResult *)refreshResult;
  37. @end
  38. /// The class calls `tokenRefreshHandler` periodically to keep FAC token fresh to reduce FAC token
  39. /// exchange overhead for product requests.
  40. @interface FIRAppCheckTokenRefresher : NSObject <FIRAppCheckTokenRefresherProtocol>
  41. - (instancetype)init NS_UNAVAILABLE;
  42. /// The designated initializer.
  43. /// @param refreshResult A previous token refresh attempt result.
  44. /// @param settings An object that handles Firebase app check settings.
  45. - (instancetype)initWithRefreshResult:(FIRAppCheckTokenRefreshResult *)refreshResult
  46. timerProvider:(FIRTimerProvider)timerProvider
  47. settings:(id<FIRAppCheckSettingsProtocol>)settings
  48. NS_DESIGNATED_INITIALIZER;
  49. /// A convenience initializer with a timer provider returning an instance of `FIRAppCheckTimer`.
  50. - (instancetype)initWithRefreshResult:(FIRAppCheckTokenRefreshResult *)refreshResult
  51. settings:(id<FIRAppCheckSettingsProtocol>)settings;
  52. @end
  53. NS_ASSUME_NONNULL_END