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 |
|
|
63 |
|
9febd9
|
64 |
/** |
W |
65 |
Represents an immutable access token for using Facebook services. |
bad748
|
66 |
*/ |
W |
67 |
@interface FBSDKAccessToken : NSObject<FBSDKCopying, NSSecureCoding> |
|
68 |
|
9febd9
|
69 |
/** |
W |
70 |
Returns the app ID. |
bad748
|
71 |
*/ |
W |
72 |
@property (readonly, copy, nonatomic) NSString *appID; |
|
73 |
|
9febd9
|
74 |
/** |
W |
75 |
Returns the known declined permissions. |
bad748
|
76 |
*/ |
W |
77 |
@property (readonly, copy, nonatomic) NSSet *declinedPermissions; |
|
78 |
|
9febd9
|
79 |
/** |
W |
80 |
Returns the expiration date. |
bad748
|
81 |
*/ |
W |
82 |
@property (readonly, copy, nonatomic) NSDate *expirationDate; |
|
83 |
|
9febd9
|
84 |
/** |
W |
85 |
Returns the known granted permissions. |
bad748
|
86 |
*/ |
W |
87 |
@property (readonly, copy, nonatomic) NSSet *permissions; |
|
88 |
|
9febd9
|
89 |
/** |
W |
90 |
Returns the date the token was last refreshed. |
bad748
|
91 |
*/ |
W |
92 |
@property (readonly, copy, nonatomic) NSDate *refreshDate; |
|
93 |
|
9febd9
|
94 |
/** |
W |
95 |
Returns the opaque token string. |
bad748
|
96 |
*/ |
W |
97 |
@property (readonly, copy, nonatomic) NSString *tokenString; |
|
98 |
|
9febd9
|
99 |
/** |
W |
100 |
Returns the user ID. |
bad748
|
101 |
*/ |
W |
102 |
@property (readonly, copy, nonatomic) NSString *userID; |
|
103 |
|
|
104 |
- (instancetype)init NS_UNAVAILABLE; |
|
105 |
+ (instancetype)new NS_UNAVAILABLE; |
|
106 |
|
9febd9
|
107 |
/** |
W |
108 |
Initializes a new instance. |
|
109 |
- Parameter tokenString: the opaque token string. |
|
110 |
- Parameter permissions: the granted permissions. Note this is converted to NSSet and is only |
bad748
|
111 |
an NSArray for the convenience of literal syntax. |
9febd9
|
112 |
- Parameter declinedPermissions: the declined permissions. Note this is converted to NSSet and is only |
bad748
|
113 |
an NSArray for the convenience of literal syntax. |
9febd9
|
114 |
- Parameter appID: the app ID. |
W |
115 |
- Parameter userID: the user ID. |
|
116 |
- Parameter expirationDate: the optional expiration date (defaults to distantFuture). |
|
117 |
- Parameter refreshDate: the optional date the token was last refreshed (defaults to today). |
|
118 |
|
|
119 |
This initializer should only be used for advanced apps that |
bad748
|
120 |
manage tokens explicitly. Typical login flows only need to use `FBSDKLoginManager` |
W |
121 |
along with `+currentAccessToken`. |
|
122 |
*/ |
|
123 |
- (instancetype)initWithTokenString:(NSString *)tokenString |
|
124 |
permissions:(NSArray *)permissions |
|
125 |
declinedPermissions:(NSArray *)declinedPermissions |
|
126 |
appID:(NSString *)appID |
|
127 |
userID:(NSString *)userID |
|
128 |
expirationDate:(NSDate *)expirationDate |
|
129 |
refreshDate:(NSDate *)refreshDate |
|
130 |
NS_DESIGNATED_INITIALIZER; |
|
131 |
|
9febd9
|
132 |
/** |
W |
133 |
Convenience getter to determine if a permission has been granted |
|
134 |
- Parameter permission: The permission to check. |
bad748
|
135 |
*/ |
W |
136 |
- (BOOL)hasGranted:(NSString *)permission; |
|
137 |
|
9febd9
|
138 |
/** |
W |
139 |
Compares the receiver to another FBSDKAccessToken |
|
140 |
- Parameter token: The other token |
|
141 |
- Returns: YES if the receiver's values are equal to the other token's values; otherwise NO |
bad748
|
142 |
*/ |
W |
143 |
- (BOOL)isEqualToAccessToken:(FBSDKAccessToken *)token; |
|
144 |
|
9febd9
|
145 |
/** |
W |
146 |
Returns the "global" access token that represents the currently logged in user. |
|
147 |
|
|
148 |
The `currentAccessToken` is a convenient representation of the token of the |
bad748
|
149 |
current user and is used by other SDK components (like `FBSDKLoginManager`). |
W |
150 |
*/ |
|
151 |
+ (FBSDKAccessToken *)currentAccessToken; |
|
152 |
|
9febd9
|
153 |
/** |
W |
154 |
Sets the "global" access token that represents the currently logged in user. |
|
155 |
- Parameter token: The access token to set. |
|
156 |
|
|
157 |
This will broadcast a notification and save the token to the app keychain. |
bad748
|
158 |
*/ |
W |
159 |
+ (void)setCurrentAccessToken:(FBSDKAccessToken *)token; |
|
160 |
|
9febd9
|
161 |
/** |
W |
162 |
Refresh the current access token's permission state and extend the token's expiration date, |
bad748
|
163 |
if possible. |
9febd9
|
164 |
- Parameter completionHandler: an optional callback handler that can surface any errors related to permission refreshing. |
W |
165 |
|
|
166 |
On a successful refresh, the currentAccessToken will be updated so you typically only need to |
bad748
|
167 |
observe the `FBSDKAccessTokenDidChangeNotification` notification. |
W |
168 |
|
|
169 |
If a token is already expired, it cannot be refreshed. |
|
170 |
*/ |
|
171 |
+ (void)refreshCurrentAccessToken:(FBSDKGraphRequestHandler)completionHandler; |
|
172 |
|
|
173 |
@end |