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