FIRInternalAppCheckProvider.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2023 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 "FirebaseAppCheck/Sources/Core/FIRInternalAppCheckProvider.h"
  17. #import "FirebaseAppCheck/Sources/Core/FIRAppCheckToken+Internal.h"
  18. #import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckProvider.h"
  19. @interface FIRInternalAppCheckProvider ()
  20. @property(nonatomic, readonly) id<FIRAppCheckProvider> appCheckProvider;
  21. @end
  22. @implementation FIRInternalAppCheckProvider
  23. - (instancetype)initWithAppCheckProvider:(id<FIRAppCheckProvider>)appCheckProvider {
  24. if (self = [super init]) {
  25. _appCheckProvider = appCheckProvider;
  26. }
  27. return self;
  28. }
  29. - (void)getTokenWithCompletion:(void (^)(GACAppCheckToken *_Nullable, NSError *_Nullable))handler {
  30. [self.appCheckProvider
  31. getTokenWithCompletion:^(FIRAppCheckToken *_Nullable token, NSError *_Nullable error) {
  32. handler([token internalToken], error);
  33. }];
  34. }
  35. - (void)getLimitedUseTokenWithCompletion:(nonnull void (^)(GACAppCheckToken *_Nullable,
  36. NSError *_Nullable))handler {
  37. if ([self.appCheckProvider respondsToSelector:@selector(getLimitedUseTokenWithCompletion:)]) {
  38. [self.appCheckProvider getLimitedUseTokenWithCompletion:^(FIRAppCheckToken *_Nullable token,
  39. NSError *_Nullable error) {
  40. handler([token internalToken], error);
  41. }];
  42. } else {
  43. [self getTokenWithCompletion:handler];
  44. }
  45. }
  46. @end