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