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 |
|
|
21 |
#import <FBSDKCoreKit/FBSDKCopying.h> |
|
22 |
#import <FBSDKCoreKit/FBSDKGraphRequestConnection.h> |
13e53a
|
23 |
|
H |
24 |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 |
bad748
|
25 |
|
9febd9
|
26 |
/** |
W |
27 |
Notification indicating that the `currentAccessToken` has changed. |
|
28 |
|
|
29 |
the userInfo dictionary of the notification will contain keys |
bad748
|
30 |
`FBSDKAccessTokenChangeOldKey` and |
W |
31 |
`FBSDKAccessTokenChangeNewKey`. |
|
32 |
*/ |
13e53a
|
33 |
FOUNDATION_EXPORT NSNotificationName const FBSDKAccessTokenDidChangeNotification; |
H |
34 |
|
|
35 |
#else |
|
36 |
|
|
37 |
/** |
|
38 |
Notification indicating that the `currentAccessToken` has changed. |
|
39 |
|
|
40 |
the userInfo dictionary of the notification will contain keys |
|
41 |
`FBSDKAccessTokenChangeOldKey` and |
|
42 |
`FBSDKAccessTokenChangeNewKey`. |
|
43 |
*/ |
|
44 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidChangeNotification; |
|
45 |
|
|
46 |
#endif |
bad748
|
47 |
|
9febd9
|
48 |
/** |
W |
49 |
A key in the notification's userInfo that will be set |
bad748
|
50 |
if and only if the user ID changed between the old and new tokens. |
9febd9
|
51 |
|
W |
52 |
Token refreshes can occur automatically with the SDK |
bad748
|
53 |
which do not change the user. If you're only interested in user |
W |
54 |
changes (such as logging out), you should check for the existence |
|
55 |
of this key. The value is a NSNumber with a boolValue. |
|
56 |
|
|
57 |
On a fresh start of the app where the SDK reads in the cached value |
|
58 |
of an access token, this key will also exist since the access token |
|
59 |
is moving from a null state (no user) to a non-null state (user). |
|
60 |
*/ |
13e53a
|
61 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidChangeUserIDKey; |
H |
62 |
|
|
63 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidChangeUserID |
|
64 |
DEPRECATED_MSG_ATTRIBUTE("Renamed `FBSDKAccessTokenDidChangeUserIDKey`"); |
bad748
|
65 |
|
W |
66 |
/* |
9febd9
|
67 |
key in notification's userInfo object for getting the old token. |
W |
68 |
|
|
69 |
If there was no old token, the key will not be present. |
bad748
|
70 |
*/ |
13e53a
|
71 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenChangeOldKey; |
bad748
|
72 |
|
W |
73 |
/* |
9febd9
|
74 |
key in notification's userInfo object for getting the new token. |
W |
75 |
|
|
76 |
If there is no new token, the key will not be present. |
bad748
|
77 |
*/ |
13e53a
|
78 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenChangeNewKey; |
bad748
|
79 |
|
9f077b
|
80 |
/* |
H |
81 |
A key in the notification's userInfo that will be set |
|
82 |
if and only if the token has expired. |
|
83 |
*/ |
13e53a
|
84 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidExpireKey; |
H |
85 |
|
|
86 |
FOUNDATION_EXPORT NSString *const FBSDKAccessTokenDidExpire |
|
87 |
DEPRECATED_MSG_ATTRIBUTE("Renamed `FBSDKAccessTokenDidExpireKey`"); |
9f077b
|
88 |
|
bad748
|
89 |
|
9febd9
|
90 |
/** |
W |
91 |
Represents an immutable access token for using Facebook services. |
bad748
|
92 |
*/ |
W |
93 |
@interface FBSDKAccessToken : NSObject<FBSDKCopying, NSSecureCoding> |
|
94 |
|
9febd9
|
95 |
/** |
W |
96 |
Returns the app ID. |
bad748
|
97 |
*/ |
W |
98 |
@property (readonly, copy, nonatomic) NSString *appID; |
13e53a
|
99 |
|
H |
100 |
/** |
|
101 |
Returns the expiration date for data access |
|
102 |
*/ |
|
103 |
@property (readonly, copy, nonatomic) NSDate *dataAccessExpirationDate; |
bad748
|
104 |
|
9febd9
|
105 |
/** |
W |
106 |
Returns the known declined permissions. |
bad748
|
107 |
*/ |
W |
108 |
@property (readonly, copy, nonatomic) NSSet *declinedPermissions; |
|
109 |
|
9febd9
|
110 |
/** |
W |
111 |
Returns the expiration date. |
bad748
|
112 |
*/ |
W |
113 |
@property (readonly, copy, nonatomic) NSDate *expirationDate; |
|
114 |
|
9febd9
|
115 |
/** |
W |
116 |
Returns the known granted permissions. |
bad748
|
117 |
*/ |
W |
118 |
@property (readonly, copy, nonatomic) NSSet *permissions; |
|
119 |
|
9febd9
|
120 |
/** |
W |
121 |
Returns the date the token was last refreshed. |
bad748
|
122 |
*/ |
W |
123 |
@property (readonly, copy, nonatomic) NSDate *refreshDate; |
|
124 |
|
9febd9
|
125 |
/** |
W |
126 |
Returns the opaque token string. |
bad748
|
127 |
*/ |
W |
128 |
@property (readonly, copy, nonatomic) NSString *tokenString; |
|
129 |
|
9febd9
|
130 |
/** |
W |
131 |
Returns the user ID. |
bad748
|
132 |
*/ |
W |
133 |
@property (readonly, copy, nonatomic) NSString *userID; |
9f077b
|
134 |
|
H |
135 |
/** |
|
136 |
Returns whether the access token is expired by checking its expirationDate property |
|
137 |
*/ |
|
138 |
@property (readonly, assign, nonatomic, getter = isExpired) BOOL expired; |
bad748
|
139 |
|
13e53a
|
140 |
/** |
H |
141 |
Returns whether user data access is still active for the given access token |
|
142 |
*/ |
|
143 |
@property (readonly, assign, nonatomic, getter = isDataAccessExpired) BOOL dataAccessExpired; |
|
144 |
|
bad748
|
145 |
- (instancetype)init NS_UNAVAILABLE; |
W |
146 |
+ (instancetype)new NS_UNAVAILABLE; |
|
147 |
|
9febd9
|
148 |
/** |
13e53a
|
149 |
Initializes a new instance. |
H |
150 |
@param tokenString the opaque token string. |
|
151 |
@param permissions the granted permissions. Note this is converted to NSSet and is only |
|
152 |
an NSArray for the convenience of literal syntax. |
|
153 |
@param declinedPermissions the declined permissions. Note this is converted to NSSet and is only |
|
154 |
an NSArray for the convenience of literal syntax. |
|
155 |
@param appID the app ID. |
|
156 |
@param userID the user ID. |
|
157 |
@param expirationDate the optional expiration date (defaults to distantFuture). |
|
158 |
@param refreshDate the optional date the token was last refreshed (defaults to today). |
|
159 |
|
|
160 |
This initializer should only be used for advanced apps that |
|
161 |
manage tokens explicitly. Typical login flows only need to use `FBSDKLoginManager` |
|
162 |
along with `+currentAccessToken`. |
|
163 |
*/ |
|
164 |
- (instancetype)initWithTokenString:(NSString *)tokenString |
|
165 |
permissions:(NSArray *)permissions |
|
166 |
declinedPermissions:(NSArray *)declinedPermissions |
|
167 |
appID:(NSString *)appID |
|
168 |
userID:(NSString *)userID |
|
169 |
expirationDate:(NSDate *)expirationDate |
|
170 |
refreshDate:(NSDate *)refreshDate; |
|
171 |
|
|
172 |
/** |
9febd9
|
173 |
Initializes a new instance. |
13e53a
|
174 |
@param tokenString the opaque token string. |
H |
175 |
@param permissions the granted permissions. Note this is converted to NSSet and is only |
bad748
|
176 |
an NSArray for the convenience of literal syntax. |
13e53a
|
177 |
@param declinedPermissions the declined permissions. Note this is converted to NSSet and is only |
bad748
|
178 |
an NSArray for the convenience of literal syntax. |
13e53a
|
179 |
@param appID the app ID. |
H |
180 |
@param userID the user ID. |
|
181 |
@param expirationDate the optional expiration date (defaults to distantFuture). |
|
182 |
@param refreshDate the optional date the token was last refreshed (defaults to today). |
|
183 |
@param dataAccessExpirationDate the date which data access will expire for the given user |
|
184 |
(defaults to distantFuture). |
9febd9
|
185 |
|
W |
186 |
This initializer should only be used for advanced apps that |
bad748
|
187 |
manage tokens explicitly. Typical login flows only need to use `FBSDKLoginManager` |
W |
188 |
along with `+currentAccessToken`. |
|
189 |
*/ |
|
190 |
- (instancetype)initWithTokenString:(NSString *)tokenString |
|
191 |
permissions:(NSArray *)permissions |
|
192 |
declinedPermissions:(NSArray *)declinedPermissions |
|
193 |
appID:(NSString *)appID |
|
194 |
userID:(NSString *)userID |
|
195 |
expirationDate:(NSDate *)expirationDate |
|
196 |
refreshDate:(NSDate *)refreshDate |
13e53a
|
197 |
dataAccessExpirationDate:(NSDate *)dataAccessExpirationDate |
bad748
|
198 |
NS_DESIGNATED_INITIALIZER; |
W |
199 |
|
9febd9
|
200 |
/** |
W |
201 |
Convenience getter to determine if a permission has been granted |
13e53a
|
202 |
@param permission The permission to check. |
bad748
|
203 |
*/ |
W |
204 |
- (BOOL)hasGranted:(NSString *)permission; |
|
205 |
|
9febd9
|
206 |
/** |
W |
207 |
Compares the receiver to another FBSDKAccessToken |
13e53a
|
208 |
@param token The other token |
H |
209 |
@return YES if the receiver's values are equal to the other token's values; otherwise NO |
bad748
|
210 |
*/ |
W |
211 |
- (BOOL)isEqualToAccessToken:(FBSDKAccessToken *)token; |
|
212 |
|
9febd9
|
213 |
/** |
W |
214 |
Returns the "global" access token that represents the currently logged in user. |
|
215 |
|
|
216 |
The `currentAccessToken` is a convenient representation of the token of the |
bad748
|
217 |
current user and is used by other SDK components (like `FBSDKLoginManager`). |
W |
218 |
*/ |
|
219 |
+ (FBSDKAccessToken *)currentAccessToken; |
|
220 |
|
9febd9
|
221 |
/** |
9f077b
|
222 |
Returns YES if currentAccessToken is not nil AND currentAccessToken is not expired |
H |
223 |
|
|
224 |
*/ |
|
225 |
+ (BOOL)currentAccessTokenIsActive; |
|
226 |
|
|
227 |
/** |
9febd9
|
228 |
Sets the "global" access token that represents the currently logged in user. |
13e53a
|
229 |
@param token The access token to set. |
9febd9
|
230 |
|
W |
231 |
This will broadcast a notification and save the token to the app keychain. |
bad748
|
232 |
*/ |
W |
233 |
+ (void)setCurrentAccessToken:(FBSDKAccessToken *)token; |
|
234 |
|
9febd9
|
235 |
/** |
W |
236 |
Refresh the current access token's permission state and extend the token's expiration date, |
bad748
|
237 |
if possible. |
13e53a
|
238 |
@param completionHandler an optional callback handler that can surface any errors related to permission refreshing. |
9febd9
|
239 |
|
W |
240 |
On a successful refresh, the currentAccessToken will be updated so you typically only need to |
bad748
|
241 |
observe the `FBSDKAccessTokenDidChangeNotification` notification. |
W |
242 |
|
|
243 |
If a token is already expired, it cannot be refreshed. |
|
244 |
*/ |
|
245 |
+ (void)refreshCurrentAccessToken:(FBSDKGraphRequestHandler)completionHandler; |
|
246 |
|
|
247 |
@end |