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