1 |
efrain |
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 |
|
|
|
17 |
#import <Foundation/Foundation.h>
|
|
|
18 |
|
|
|
19 |
@class FIRMessagingAPNSInfo;
|
|
|
20 |
@class FIRMessagingAuthKeychain;
|
|
|
21 |
@class FIRMessagingTokenInfo;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* This class is responsible for retrieving and saving `FIRMessagingTokenInfo` objects from the
|
|
|
25 |
* keychain. The keychain keys that are used are:
|
|
|
26 |
* Account: <Main App Bundle ID> (e.g. com.mycompany.myapp)
|
|
|
27 |
* Service: <Sender ID>:<Scope> (e.g. 1234567890:*)
|
|
|
28 |
*/
|
|
|
29 |
@interface FIRMessagingTokenStore : NSObject
|
|
|
30 |
|
|
|
31 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
32 |
|
|
|
33 |
- (instancetype)init;
|
|
|
34 |
|
|
|
35 |
#pragma mark - Get
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Get the cached token from the Keychain.
|
|
|
39 |
*
|
|
|
40 |
* @param authorizedEntity The authorized entity for the token.
|
|
|
41 |
* @param scope The scope for the token.
|
|
|
42 |
*
|
|
|
43 |
* @return The cached token info if any for the given authorizedEntity and scope else
|
|
|
44 |
* nil.
|
|
|
45 |
*/
|
|
|
46 |
- (nullable FIRMessagingTokenInfo *)tokenInfoWithAuthorizedEntity:(NSString *)authorizedEntity
|
|
|
47 |
scope:(NSString *)scope;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Return all cached token infos from the Keychain.
|
|
|
51 |
*
|
|
|
52 |
* @return The cached token infos, if any, that are stored in the Keychain.
|
|
|
53 |
*/
|
|
|
54 |
- (NSArray<FIRMessagingTokenInfo *> *)cachedTokenInfos;
|
|
|
55 |
|
|
|
56 |
#pragma mark - Save
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Save the instanceID token info to the persistent store.
|
|
|
60 |
*
|
|
|
61 |
* @param tokenInfo The token info to store.
|
|
|
62 |
* @param handler The callback handler which is invoked when token saving is complete,
|
|
|
63 |
* with an error if there is any.
|
|
|
64 |
*/
|
|
|
65 |
- (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
|
|
|
66 |
handler:(nullable void (^)(NSError *))handler;
|
|
|
67 |
|
|
|
68 |
#pragma mark - Delete
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Remove the cached token from Keychain.
|
|
|
72 |
*
|
|
|
73 |
* @param authorizedEntity The authorized entity for the token.
|
|
|
74 |
* @param scope The scope for the token.
|
|
|
75 |
*
|
|
|
76 |
*/
|
|
|
77 |
- (void)removeTokenWithAuthorizedEntity:(NSString *)authorizedEntity scope:(NSString *)scope;
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* Remove all the cached tokens from the Keychain.
|
|
|
81 |
* @param handler The callback handler which is invoked when tokens deletion is complete,
|
|
|
82 |
* with an error if there is any.
|
|
|
83 |
*
|
|
|
84 |
*/
|
|
|
85 |
- (void)removeAllTokensWithHandler:(nullable void (^)(NSError *))handler;
|
|
|
86 |
|
|
|
87 |
/*
|
|
|
88 |
* Only save to local cache but not keychain. This is used when old
|
|
|
89 |
* InstanceID SDK updates the token in the keychain, Messaging
|
|
|
90 |
* should update its cache without writing to keychain again.
|
|
|
91 |
* @param tokenInfo The token info need to be updated in the cache.
|
|
|
92 |
*/
|
|
|
93 |
- (void)saveTokenInfoInCache:(FIRMessagingTokenInfo *)tokenInfo;
|
|
|
94 |
|
|
|
95 |
NS_ASSUME_NONNULL_END
|
|
|
96 |
|
|
|
97 |
@end
|