FIRStorageTokenAuthorizer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2017 Google
  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. #if SWIFT_PACKAGE
  17. @import GTMSessionFetcherCore;
  18. #else
  19. #import <GTMSessionFetcher/GTMSessionFetcherService.h>
  20. #endif
  21. @protocol FIRAuthInterop;
  22. @protocol FIRAppCheckInterop;
  23. NS_ASSUME_NONNULL_BEGIN
  24. /**
  25. * Wrapper class for FIRAuthInterop that implements the GTMFetcherAuthorizationProtocol,
  26. * so as to easily provide GTMSessionFetcher fetches a Firebase Authentication JWT
  27. * for the current logged in user. Handles token expiration and other failure cases.
  28. * If no authentication provider exists or no token is found, no token is added
  29. * and the request is passed.
  30. */
  31. #pragma clang diagnostic push
  32. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  33. @interface FIRStorageTokenAuthorizer : NSObject <GTMFetcherAuthorizationProtocol>
  34. #pragma clang diagnostic pop
  35. /**
  36. * Initializes the token authorizer with an instance of FIRApp.
  37. * @param googleAppID The Google AppID of the app to send with the request.
  38. * @param auth An instance that provides access to Auth functionality, if it exists.
  39. * @param appCheck An instance that provides access to AppCheck functionality, if it exists.
  40. * @return Returns an instance of FIRStorageTokenAuthorizer which adds the appropriate
  41. * "Authorization" header to all outbound requests. Note that a token may not be added
  42. * if the Auth instance is nil. This allows for unauthenticated access, if Firebase
  43. * Storage rules allow for it.
  44. */
  45. - (instancetype)initWithGoogleAppID:(NSString *)googleAppID
  46. fetcherService:(GTMSessionFetcherService *)service
  47. authProvider:(nullable id<FIRAuthInterop>)auth
  48. appCheck:(nullable id<FIRAppCheckInterop>)appCheck;
  49. @end
  50. NS_ASSUME_NONNULL_END