Sin descripción

FIRInstanceIDTokenStore.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <Foundation/Foundation.h>
  17. @class FIRInstanceIDAPNSInfo;
  18. @class FIRInstanceIDAuthKeychain;
  19. @class FIRInstanceIDTokenInfo;
  20. /**
  21. * This class is responsible for retrieving and saving `FIRInstanceIDTokenInfo` objects from the
  22. * keychain. The keychain keys that are used are:
  23. * Account: <Main App Bundle ID> (e.g. com.mycompany.myapp)
  24. * Service: <Sender ID>:<Scope> (e.g. 1234567890:*)
  25. */
  26. @interface FIRInstanceIDTokenStore : NSObject
  27. NS_ASSUME_NONNULL_BEGIN
  28. /**
  29. * Create a default InstanceID token store. Uses a valid Keychain object as it's
  30. * persistent backing store.
  31. *
  32. * @return A valid token store object.
  33. */
  34. + (instancetype)defaultStore;
  35. - (instancetype)init __attribute__((unavailable("Use -initWithKeychain: instead.")));
  36. /**
  37. * Initialize a token store object with a Keychain object. Used for testing.
  38. *
  39. * @param keychain The Keychain object to use as the backing store for tokens.
  40. *
  41. * @return A valid token store object with the given Keychain as backing store.
  42. */
  43. - (instancetype)initWithKeychain:(FIRInstanceIDAuthKeychain *)keychain;
  44. #pragma mark - Get
  45. /**
  46. * Get the cached token from the Keychain.
  47. *
  48. * @param authorizedEntity The authorized entity for the token.
  49. * @param scope The scope for the token.
  50. *
  51. * @return The cached token info if any for the given authorizedEntity and scope else
  52. * nil.
  53. */
  54. - (nullable FIRInstanceIDTokenInfo *)tokenInfoWithAuthorizedEntity:(NSString *)authorizedEntity
  55. scope:(NSString *)scope;
  56. /**
  57. * Return all cached token infos from the Keychain.
  58. *
  59. * @return The cached token infos, if any, that are stored in the Keychain.
  60. */
  61. - (NSArray<FIRInstanceIDTokenInfo *> *)cachedTokenInfos;
  62. #pragma mark - Save
  63. /**
  64. * Save the instanceID token info to the persistent store.
  65. *
  66. * @param tokenInfo The token info to store.
  67. * @param handler The callback handler which is invoked when token saving is complete,
  68. * with an error if there is any.
  69. */
  70. - (void)saveTokenInfo:(FIRInstanceIDTokenInfo *)tokenInfo
  71. handler:(nullable void (^)(NSError *))handler;
  72. #pragma mark - Delete
  73. /**
  74. * Remove the cached token from Keychain.
  75. *
  76. * @param authorizedEntity The authorized entity for the token.
  77. * @param scope The scope for the token.
  78. *
  79. */
  80. - (void)removeTokenWithAuthorizedEntity:(NSString *)authorizedEntity scope:(NSString *)scope;
  81. /**
  82. * Remove all the cached tokens from the Keychain.
  83. * @param handler The callback handler which is invoked when tokens deletion is complete,
  84. * with an error if there is any.
  85. *
  86. */
  87. - (void)removeAllTokensWithHandler:(nullable void (^)(NSError *))handler;
  88. NS_ASSUME_NONNULL_END
  89. @end