FIRStorageTokenAuthorizer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. @interface FIRStorageTokenAuthorizer : NSObject <GTMFetcherAuthorizationProtocol>
  32. /**
  33. * Initializes the token authorizer with an instance of FIRApp.
  34. * @param googleAppID The Google AppID of the app to send with the request.
  35. * @param auth An instance that provides access to Auth functionality, if it exists.
  36. * @param appCheck An instance that provides access to AppCheck functionality, if it exists.
  37. * @return Returns an instance of FIRStorageTokenAuthorizer which adds the appropriate
  38. * "Authorization" header to all outbound requests. Note that a token may not be added
  39. * if the Auth instance is nil. This allows for unauthenticated access, if Firebase
  40. * Storage rules allow for it.
  41. */
  42. - (instancetype)initWithGoogleAppID:(NSString *)googleAppID
  43. fetcherService:(GTMSessionFetcherService *)service
  44. authProvider:(nullable id<FIRAuthInterop>)auth
  45. appCheck:(nullable id<FIRAppCheckInterop>)appCheck;
  46. @end
  47. NS_ASSUME_NONNULL_END