AuthProviders.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2019 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. #import <UIKit/UIKit.h>
  17. @class FIRAuthCredential;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @typedef AuthCredentialCallback
  20. @brief The type of block invoked when a @c FIRAuthCredential object is ready or an error has
  21. occurred.
  22. @param credential The auth credential if any.
  23. @param error The error which occurred, if any.
  24. */
  25. typedef void (^AuthCredentialCallback)(FIRAuthCredential *_Nullable credential,
  26. NSError *_Nullable error);
  27. /** @protocol AuthProvider
  28. @brief A common interface for auth providers to be used by the sample app.
  29. */
  30. @protocol AuthProvider <NSObject>
  31. /** @fn getAuthCredentialWithPresentingViewController:callback:
  32. @brief Gets a @c FIRAuthCredential instance for use with Firebase headless API by signing in.
  33. @param viewController The view controller to present the UI.
  34. @param callback A block which is invoked when the sign-in flow finishes. Invoked asynchronously
  35. on an unspecified thread in the future.
  36. */
  37. - (void)getAuthCredentialWithPresentingViewController:(UIViewController *)viewController
  38. callback:(AuthCredentialCallback)callback;
  39. /** @fn signOut
  40. @brief Logs out the current provider session, which invalidates any cached crendential.
  41. */
  42. - (void)signOut;
  43. @end
  44. /** @class AuthProviders
  45. @brief Namespace for @c AuthProvider instances.
  46. */
  47. @interface AuthProviders : NSObject
  48. /** @fn google
  49. @brief Returns a Google auth provider.
  50. */
  51. + (id<AuthProvider>)google;
  52. /** @fn facebook
  53. @brief Returns a Facebook auth provider.
  54. */
  55. + (id<AuthProvider>)facebook;
  56. /** @fn init
  57. @brief This class is not supposed to be instantiated.
  58. */
  59. - (nullable instancetype)init NS_UNAVAILABLE;
  60. @end
  61. NS_ASSUME_NONNULL_END