commit | author | age
|
bad748
|
1 |
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
W |
2 |
// |
|
3 |
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, |
|
4 |
// copy, modify, and distribute this software in source code or binary form for use |
|
5 |
// in connection with the web services and APIs provided by Facebook. |
|
6 |
// |
|
7 |
// As with any software that integrates with the Facebook platform, your use of |
|
8 |
// this software is subject to the Facebook Developer Principles and Policies |
|
9 |
// [http://developers.facebook.com/policy/]. This copyright notice shall be |
|
10 |
// included in all copies or substantial portions of the software. |
|
11 |
// |
|
12 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
13 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
14 |
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
15 |
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
16 |
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
17 |
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
18 |
|
|
19 |
#import <Foundation/Foundation.h> |
|
20 |
|
49b883
|
21 |
#import "FBSDKCopying.h" |
L |
22 |
|
|
23 |
#ifdef BUCK |
bad748
|
24 |
#import <FBSDKCoreKit/FBSDKGraphRequestConnection.h> |
49b883
|
25 |
#else |
L |
26 |
#import "FBSDKGraphRequestConnection.h" |
|
27 |
#endif |
13e53a
|
28 |
|
e81c27
|
29 |
NS_ASSUME_NONNULL_BEGIN |
H |
30 |
|
13e53a
|
31 |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 |
bad748
|
32 |
|
9febd9
|
33 |
/** |
W |
34 |
Notification indicating that the `currentAccessToken` has changed. |
|
35 |
|
|
36 |
the userInfo dictionary of the notification will contain keys |
bad748
|
37 |
`FBSDKAccessTokenChangeOldKey` and |
W |
38 |
`FBSDKAccessTokenChangeNewKey`. |
|
39 |
*/ |
e81c27
|
40 |
FOUNDATION_EXPORT NSNotificationName const FBSDKAccessTokenDidChangeNotification |
H |
41 |
NS_SWIFT_NAME(AccessTokenDidChange); |
13e53a
|
42 |
|
H |
43 |
#else |
|
44 |
|
|
45 |
/** |
e81c27
|
46 |
Notification indicating that the `currentAccessToken` has changed. |
13e53a
|
47 |
|
H |
48 |
the userInfo dictionary of the notification will contain keys |
|
49 |
`FBSDKAccessTokenChangeOldKey` and |
|
50 |
`FBSDKAccessTokenChangeNewKey`. |
|
51 |
*/ |
e81c27
|
52 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidChangeNotification |
H |
53 |
NS_SWIFT_NAME(AccessTokenDidChangeNotification); |
13e53a
|
54 |
#endif |
bad748
|
55 |
|
9febd9
|
56 |
/** |
W |
57 |
A key in the notification's userInfo that will be set |
bad748
|
58 |
if and only if the user ID changed between the old and new tokens. |
9febd9
|
59 |
|
W |
60 |
Token refreshes can occur automatically with the SDK |
bad748
|
61 |
which do not change the user. If you're only interested in user |
W |
62 |
changes (such as logging out), you should check for the existence |
|
63 |
of this key. The value is a NSNumber with a boolValue. |
|
64 |
|
|
65 |
On a fresh start of the app where the SDK reads in the cached value |
|
66 |
of an access token, this key will also exist since the access token |
|
67 |
is moving from a null state (no user) to a non-null state (user). |
|
68 |
*/ |
e81c27
|
69 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidChangeUserIDKey |
H |
70 |
NS_SWIFT_NAME(AccessTokenDidChangeUserIDKey); |
bad748
|
71 |
|
W |
72 |
/* |
9febd9
|
73 |
key in notification's userInfo object for getting the old token. |
W |
74 |
|
|
75 |
If there was no old token, the key will not be present. |
bad748
|
76 |
*/ |
e81c27
|
77 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenChangeOldKey |
H |
78 |
NS_SWIFT_NAME(AccessTokenChangeOldKey); |
bad748
|
79 |
|
W |
80 |
/* |
9febd9
|
81 |
key in notification's userInfo object for getting the new token. |
W |
82 |
|
|
83 |
If there is no new token, the key will not be present. |
bad748
|
84 |
*/ |
e81c27
|
85 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenChangeNewKey |
H |
86 |
NS_SWIFT_NAME(AccessTokenChangeNewKey); |
bad748
|
87 |
|
9f077b
|
88 |
/* |
H |
89 |
A key in the notification's userInfo that will be set |
|
90 |
if and only if the token has expired. |
|
91 |
*/ |
e81c27
|
92 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidExpireKey |
H |
93 |
NS_SWIFT_NAME(AccessTokenDidExpireKey); |
9f077b
|
94 |
|
bad748
|
95 |
|
9febd9
|
96 |
/** |
W |
97 |
Represents an immutable access token for using Facebook services. |
bad748
|
98 |
*/ |
e81c27
|
99 |
NS_SWIFT_NAME(AccessToken) |
bad748
|
100 |
@interface FBSDKAccessToken : NSObject<FBSDKCopying, NSSecureCoding> |
e81c27
|
101 |
|
H |
102 |
|
|
103 |
/** |
|
104 |
The "global" access token that represents the currently logged in user. |
|
105 |
|
|
106 |
The `currentAccessToken` is a convenient representation of the token of the |
|
107 |
current user and is used by other SDK components (like `FBSDKLoginManager`). |
|
108 |
*/ |
|
109 |
@property (class, nonatomic, copy, nullable) FBSDKAccessToken *currentAccessToken; |
|
110 |
|
|
111 |
/** |
|
112 |
Returns YES if currentAccessToken is not nil AND currentAccessToken is not expired |
|
113 |
|
|
114 |
*/ |
|
115 |
@property (class, nonatomic, assign, readonly, getter=isCurrentAccessTokenActive) BOOL currentAccessTokenIsActive; |
bad748
|
116 |
|
9febd9
|
117 |
/** |
W |
118 |
Returns the app ID. |
bad748
|
119 |
*/ |
e81c27
|
120 |
@property (nonatomic, copy, readonly) NSString *appID; |
13e53a
|
121 |
|
H |
122 |
/** |
|
123 |
Returns the expiration date for data access |
|
124 |
*/ |
e81c27
|
125 |
@property (nonatomic, copy, readonly) NSDate *dataAccessExpirationDate; |
bad748
|
126 |
|
9febd9
|
127 |
/** |
W |
128 |
Returns the known declined permissions. |
bad748
|
129 |
*/ |
e81c27
|
130 |
@property (nonatomic, copy, readonly) NSSet<NSString *> *declinedPermissions |
H |
131 |
NS_REFINED_FOR_SWIFT; |
|
132 |
|
|
133 |
/** |
|
134 |
Returns the known declined permissions. |
|
135 |
*/ |
|
136 |
@property (nonatomic, copy, readonly) NSSet<NSString *> *expiredPermissions |
|
137 |
NS_REFINED_FOR_SWIFT; |
bad748
|
138 |
|
9febd9
|
139 |
/** |
W |
140 |
Returns the expiration date. |
bad748
|
141 |
*/ |
e81c27
|
142 |
@property (nonatomic, copy, readonly) NSDate *expirationDate; |
bad748
|
143 |
|
9febd9
|
144 |
/** |
W |
145 |
Returns the known granted permissions. |
bad748
|
146 |
*/ |
e81c27
|
147 |
@property (nonatomic, copy, readonly) NSSet<NSString *> *permissions |
H |
148 |
NS_REFINED_FOR_SWIFT; |
bad748
|
149 |
|
9febd9
|
150 |
/** |
W |
151 |
Returns the date the token was last refreshed. |
bad748
|
152 |
*/ |
e81c27
|
153 |
@property (nonatomic, copy, readonly) NSDate *refreshDate; |
bad748
|
154 |
|
9febd9
|
155 |
/** |
W |
156 |
Returns the opaque token string. |
bad748
|
157 |
*/ |
e81c27
|
158 |
@property (nonatomic, copy, readonly) NSString *tokenString; |
bad748
|
159 |
|
9febd9
|
160 |
/** |
W |
161 |
Returns the user ID. |
bad748
|
162 |
*/ |
e81c27
|
163 |
@property (nonatomic, copy, readonly) NSString *userID; |
9f077b
|
164 |
|
H |
165 |
/** |
49b883
|
166 |
The graph domain where this access token is valid. |
L |
167 |
*/ |
|
168 |
@property (nonatomic, copy, readonly) NSString *graphDomain; |
|
169 |
|
|
170 |
/** |
9f077b
|
171 |
Returns whether the access token is expired by checking its expirationDate property |
H |
172 |
*/ |
e81c27
|
173 |
@property (readonly, assign, nonatomic, getter=isExpired) BOOL expired; |
bad748
|
174 |
|
13e53a
|
175 |
/** |
H |
176 |
Returns whether user data access is still active for the given access token |
|
177 |
*/ |
e81c27
|
178 |
@property (readonly, assign, nonatomic, getter=isDataAccessExpired) BOOL dataAccessExpired; |
13e53a
|
179 |
|
bad748
|
180 |
- (instancetype)init NS_UNAVAILABLE; |
W |
181 |
+ (instancetype)new NS_UNAVAILABLE; |
|
182 |
|
9febd9
|
183 |
/** |
13e53a
|
184 |
Initializes a new instance. |
H |
185 |
@param tokenString the opaque token string. |
|
186 |
@param permissions the granted permissions. Note this is converted to NSSet and is only |
|
187 |
an NSArray for the convenience of literal syntax. |
|
188 |
@param declinedPermissions the declined permissions. Note this is converted to NSSet and is only |
|
189 |
an NSArray for the convenience of literal syntax. |
e81c27
|
190 |
@param expiredPermissions the expired permissions. Note this is converted to NSSet and is only |
bad748
|
191 |
an NSArray for the convenience of literal syntax. |
13e53a
|
192 |
@param appID the app ID. |
H |
193 |
@param userID the user ID. |
|
194 |
@param expirationDate the optional expiration date (defaults to distantFuture). |
|
195 |
@param refreshDate the optional date the token was last refreshed (defaults to today). |
|
196 |
@param dataAccessExpirationDate the date which data access will expire for the given user |
|
197 |
(defaults to distantFuture). |
9febd9
|
198 |
|
W |
199 |
This initializer should only be used for advanced apps that |
bad748
|
200 |
manage tokens explicitly. Typical login flows only need to use `FBSDKLoginManager` |
W |
201 |
along with `+currentAccessToken`. |
|
202 |
*/ |
|
203 |
- (instancetype)initWithTokenString:(NSString *)tokenString |
e81c27
|
204 |
permissions:(NSArray<NSString *> *)permissions |
H |
205 |
declinedPermissions:(NSArray<NSString *> *)declinedPermissions |
|
206 |
expiredPermissions:(NSArray<NSString *> *)expiredPermissions |
bad748
|
207 |
appID:(NSString *)appID |
W |
208 |
userID:(NSString *)userID |
e81c27
|
209 |
expirationDate:(nullable NSDate *)expirationDate |
H |
210 |
refreshDate:(nullable NSDate *)refreshDate |
|
211 |
dataAccessExpirationDate:(nullable NSDate *)dataAccessExpirationDate |
bad748
|
212 |
NS_DESIGNATED_INITIALIZER; |
W |
213 |
|
9febd9
|
214 |
/** |
49b883
|
215 |
Convenience initializer. |
L |
216 |
@param tokenString the opaque token string. |
|
217 |
@param permissions the granted permissions. Note this is converted to NSSet and is only |
|
218 |
an NSArray for the convenience of literal syntax. |
|
219 |
@param declinedPermissions the declined permissions. Note this is converted to NSSet and is only |
|
220 |
an NSArray for the convenience of literal syntax. |
|
221 |
@param expiredPermissions the expired permissions. Note this is converted to NSSet and is only |
|
222 |
an NSArray for the convenience of literal syntax. |
|
223 |
@param appID the app ID. |
|
224 |
@param userID the user ID. |
|
225 |
@param expirationDate the optional expiration date (defaults to distantFuture). |
|
226 |
@param refreshDate the optional date the token was last refreshed (defaults to today). |
|
227 |
@param dataAccessExpirationDate the date which data access will expire for the given user |
|
228 |
(defaults to distantFuture). |
|
229 |
@param graphDomain the domain this access token can be used in. |
|
230 |
|
|
231 |
This initializer should only be used for advanced apps that |
|
232 |
manage tokens explicitly. Typical login flows only need to use `FBSDKLoginManager` |
|
233 |
along with `+currentAccessToken`. |
|
234 |
*/ |
|
235 |
- (instancetype)initWithTokenString:(NSString *)tokenString |
|
236 |
permissions:(NSArray<NSString *> *)permissions |
|
237 |
declinedPermissions:(NSArray<NSString *> *)declinedPermissions |
|
238 |
expiredPermissions:(NSArray<NSString *> *)expiredPermissions |
|
239 |
appID:(NSString *)appID |
|
240 |
userID:(NSString *)userID |
|
241 |
expirationDate:(nullable NSDate *)expirationDate |
|
242 |
refreshDate:(nullable NSDate *)refreshDate |
|
243 |
dataAccessExpirationDate:(nullable NSDate *)dataAccessExpirationDate |
|
244 |
graphDomain:(nullable NSString *)graphDomain; |
|
245 |
|
|
246 |
/** |
9febd9
|
247 |
Convenience getter to determine if a permission has been granted |
13e53a
|
248 |
@param permission The permission to check. |
bad748
|
249 |
*/ |
e81c27
|
250 |
- (BOOL)hasGranted:(NSString *)permission |
H |
251 |
NS_SWIFT_NAME(hasGranted(permission:)); |
bad748
|
252 |
|
9febd9
|
253 |
/** |
W |
254 |
Compares the receiver to another FBSDKAccessToken |
13e53a
|
255 |
@param token The other token |
H |
256 |
@return YES if the receiver's values are equal to the other token's values; otherwise NO |
bad748
|
257 |
*/ |
W |
258 |
- (BOOL)isEqualToAccessToken:(FBSDKAccessToken *)token; |
|
259 |
|
9febd9
|
260 |
/** |
W |
261 |
Refresh the current access token's permission state and extend the token's expiration date, |
bad748
|
262 |
if possible. |
13e53a
|
263 |
@param completionHandler an optional callback handler that can surface any errors related to permission refreshing. |
9febd9
|
264 |
|
W |
265 |
On a successful refresh, the currentAccessToken will be updated so you typically only need to |
bad748
|
266 |
observe the `FBSDKAccessTokenDidChangeNotification` notification. |
W |
267 |
|
|
268 |
If a token is already expired, it cannot be refreshed. |
|
269 |
*/ |
e81c27
|
270 |
+ (void)refreshCurrentAccessToken:(nullable FBSDKGraphRequestBlock)completionHandler; |
bad748
|
271 |
|
W |
272 |
@end |
e81c27
|
273 |
|
H |
274 |
NS_ASSUME_NONNULL_END |