FIRStorageTokenAuthorizer.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. NS_ASSUME_NONNULL_BEGIN
  23. /**
  24. * Wrapper class for FIRAuthInterop that implements the GTMFetcherAuthorizationProtocol,
  25. * so as to easily provide GTMSessionFetcher fetches a Firebase Authentication JWT
  26. * for the current logged in user. Handles token expiration and other failure cases.
  27. * If no authentication provider exists or no token is found, no token is added
  28. * and the request is passed.
  29. */
  30. @interface FIRStorageTokenAuthorizer : NSObject <GTMFetcherAuthorizationProtocol>
  31. /**
  32. * Initializes the token authorizer with an instance of FIRApp.
  33. * @param googleAppID The Google AppID of the app to send with the request.
  34. * @param auth An instance that provides access to Auth functionality, if it exists.
  35. * @return Returns an instance of FIRStorageTokenAuthorizer which adds the appropriate
  36. * "Authorization" header to all outbound requests. Note that a token may not be added
  37. * if the Auth instance is nil. This allows for unauthenticated access, if Firebase
  38. * Storage rules allow for it.
  39. */
  40. - (instancetype)initWithGoogleAppID:(NSString *)googleAppID
  41. fetcherService:(GTMSessionFetcherService *)service
  42. authProvider:(nullable id<FIRAuthInterop>)auth;
  43. @end
  44. NS_ASSUME_NONNULL_END