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