You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.5 KiB

6 years ago
  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. #import "FIRUser.h"
  17. @class FIRAuth;
  18. @class FIRAuthRequestConfiguration;
  19. NS_ASSUME_NONNULL_BEGIN
  20. /** @typedef FIRRetrieveUserCallback
  21. @brief The type of block that is invoked when the construction of a user succeeds or fails.
  22. @param user The user that was constructed, or nil if user construction failed.
  23. @param error The error which occurred, or nil if the request was successful.
  24. */
  25. typedef void(^FIRRetrieveUserCallback)(FIRUser *_Nullable user, NSError *_Nullable error);
  26. @interface FIRUser () <NSSecureCoding>
  27. /** @property rawAccessToken
  28. @brief The cached access token.
  29. @remarks This method is specifically for providing the access token to internal clients during
  30. deserialization and sign-in events, and should not be used to retrieve the access token by
  31. anyone else.
  32. */
  33. @property(nonatomic, copy, readonly) NSString *rawAccessToken;
  34. /** @property auth
  35. @brief A weak reference to a FIRAuth instance associated with this instance.
  36. */
  37. @property(nonatomic, weak) FIRAuth *auth;
  38. /** @property auth
  39. @brief A strong reference to a requestConfiguration instance associated with this user instance.
  40. */
  41. @property(nonatomic, strong) FIRAuthRequestConfiguration *requestConfiguration;
  42. /** @var accessTokenExpirationDate
  43. @brief The expiration date of the cached access token.
  44. */
  45. @property(nonatomic, copy, readonly) NSDate *accessTokenExpirationDate;
  46. /** @fn retrieveUserWithAuth:accessToken:accessTokenExpirationDate:refreshToken:callback:
  47. @brief Constructs a user with Secure Token Service tokens, and obtains user details from the
  48. getAccountInfo endpoint.
  49. @param auth The associated FIRAuth instance.
  50. @param accessToken The Secure Token Service access token.
  51. @param accessTokenExpirationDate The approximate expiration date of the access token.
  52. @param refreshToken The Secure Token Service refresh token.
  53. @param anonymous Whether or not the user is anonymous.
  54. @param callback A block which is invoked when the construction succeeds or fails. Invoked
  55. asynchronously on the auth global work queue in the future.
  56. */
  57. + (void)retrieveUserWithAuth:(FIRAuth *)auth
  58. accessToken:(NSString *)accessToken
  59. accessTokenExpirationDate:(NSDate *)accessTokenExpirationDate
  60. refreshToken:(NSString *)refreshToken
  61. anonymous:(BOOL)anonymous
  62. callback:(FIRRetrieveUserCallback)callback;
  63. /** @fn internalGetTokenForcingRefresh:callback:
  64. @brief Retrieves the Firebase authentication token, possibly refreshing it if it has expired.
  65. @param forceRefresh Forces a token refresh. Useful if the token becomes invalid for some reason
  66. other than an expiration.
  67. @param callback The block to invoke when the token is available. Invoked asynchronously on the
  68. global work thread in the future.
  69. */
  70. - (void)internalGetTokenForcingRefresh:(BOOL)forceRefresh
  71. callback:(nonnull FIRAuthTokenCallback)callback;
  72. @end
  73. NS_ASSUME_NONNULL_END