FIRMessagingTokenStore.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 FIRMessagingAPNSInfo;
  18. @class FIRMessagingAuthKeychain;
  19. @class FIRMessagingTokenInfo;
  20. /**
  21. * This class is responsible for retrieving and saving `FIRMessagingTokenInfo` 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 FIRMessagingTokenStore : NSObject
  27. NS_ASSUME_NONNULL_BEGIN
  28. - (instancetype)init;
  29. #pragma mark - Get
  30. /**
  31. * Get the cached token from the Keychain.
  32. *
  33. * @param authorizedEntity The authorized entity for the token.
  34. * @param scope The scope for the token.
  35. *
  36. * @return The cached token info if any for the given authorizedEntity and scope else
  37. * nil.
  38. */
  39. - (nullable FIRMessagingTokenInfo *)tokenInfoWithAuthorizedEntity:(NSString *)authorizedEntity
  40. scope:(NSString *)scope;
  41. /**
  42. * Return all cached token infos from the Keychain.
  43. *
  44. * @return The cached token infos, if any, that are stored in the Keychain.
  45. */
  46. - (NSArray<FIRMessagingTokenInfo *> *)cachedTokenInfos;
  47. #pragma mark - Save
  48. /**
  49. * Save the instanceID token info to the persistent store.
  50. *
  51. * @param tokenInfo The token info to store.
  52. * @param handler The callback handler which is invoked when token saving is complete,
  53. * with an error if there is any.
  54. */
  55. - (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
  56. handler:(nullable void (^)(NSError *))handler;
  57. #pragma mark - Delete
  58. /**
  59. * Remove the cached token from Keychain.
  60. *
  61. * @param authorizedEntity The authorized entity for the token.
  62. * @param scope The scope for the token.
  63. *
  64. */
  65. - (void)removeTokenWithAuthorizedEntity:(NSString *)authorizedEntity scope:(NSString *)scope;
  66. /**
  67. * Remove all the cached tokens from the Keychain.
  68. * @param handler The callback handler which is invoked when tokens deletion is complete,
  69. * with an error if there is any.
  70. *
  71. */
  72. - (void)removeAllTokensWithHandler:(nullable void (^)(NSError *))handler;
  73. /*
  74. * Only save to local cache but not keychain. This is used when old
  75. * InstanceID SDK updates the token in the keychain, Messaging
  76. * should update its cache without writing to keychain again.
  77. * @param tokenInfo The token info need to be updated in the cache.
  78. */
  79. - (void)saveTokenInfoInCache:(FIRMessagingTokenInfo *)tokenInfo;
  80. NS_ASSUME_NONNULL_END
  81. @end