Wuyx
2016-12-01 a62229dd52507addd75498c136df906c43772a75
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
25 /*!
26  @abstract Notification indicating that the `currentAccessToken` has changed.
27  @discussion the userInfo dictionary of the notification will contain keys
28  `FBSDKAccessTokenChangeOldKey` and
29  `FBSDKAccessTokenChangeNewKey`.
30  */
31 FBSDK_EXTERN NSString *const FBSDKAccessTokenDidChangeNotification;
32
33 /*!
34  @abstract A key in the notification's userInfo that will be set
35   if and only if the user ID changed between the old and new tokens.
36  @discussion 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 FBSDK_EXTERN NSString *const FBSDKAccessTokenDidChangeUserID;
46
47 /*
48  @abstract key in notification's userInfo object for getting the old token.
49  @discussion If there was no old token, the key will not be present.
50  */
51 FBSDK_EXTERN NSString *const FBSDKAccessTokenChangeOldKey;
52
53 /*
54  @abstract key in notification's userInfo object for getting the new token.
55  @discussion If there is no new token, the key will not be present.
56  */
57 FBSDK_EXTERN NSString *const FBSDKAccessTokenChangeNewKey;
58
59
60 /*!
61  @class FBSDKAccessToken
62  @abstract Represents an immutable access token for using Facebook services.
63  */
64 @interface FBSDKAccessToken : NSObject<FBSDKCopying, NSSecureCoding>
65
66 /*!
67  @abstract Returns the app ID.
68  */
69 @property (readonly, copy, nonatomic) NSString *appID;
70
71 /*!
72  @abstract Returns the known declined permissions.
73  */
74 @property (readonly, copy, nonatomic) NSSet *declinedPermissions;
75
76 /*!
77  @abstract Returns the expiration date.
78  */
79 @property (readonly, copy, nonatomic) NSDate *expirationDate;
80
81 /*!
82  @abstract Returns the known granted permissions.
83  */
84 @property (readonly, copy, nonatomic) NSSet *permissions;
85
86 /*!
87  @abstract Returns the date the token was last refreshed.
88 */
89 @property (readonly, copy, nonatomic) NSDate *refreshDate;
90
91 /*!
92  @abstract Returns the opaque token string.
93  */
94 @property (readonly, copy, nonatomic) NSString *tokenString;
95
96 /*!
97  @abstract Returns the user ID.
98  */
99 @property (readonly, copy, nonatomic) NSString *userID;
100
101 - (instancetype)init NS_UNAVAILABLE;
102 + (instancetype)new NS_UNAVAILABLE;
103
104 /*!
105  @abstract Initializes a new instance.
106  @param tokenString the opaque token string.
107  @param permissions the granted permissions. Note this is converted to NSSet and is only
108  an NSArray for the convenience of literal syntax.
109  @param declinedPermissions the declined permissions. Note this is converted to NSSet and is only
110  an NSArray for the convenience of literal syntax.
111  @param appID the app ID.
112  @param userID the user ID.
113  @param expirationDate the optional expiration date (defaults to distantFuture).
114  @param refreshDate the optional date the token was last refreshed (defaults to today).
115  @discussion This initializer should only be used for advanced apps that
116  manage tokens explicitly. Typical login flows only need to use `FBSDKLoginManager`
117  along with `+currentAccessToken`.
118  */
119 - (instancetype)initWithTokenString:(NSString *)tokenString
120                         permissions:(NSArray *)permissions
121                 declinedPermissions:(NSArray *)declinedPermissions
122                               appID:(NSString *)appID
123                              userID:(NSString *)userID
124                      expirationDate:(NSDate *)expirationDate
125                         refreshDate:(NSDate *)refreshDate
126 NS_DESIGNATED_INITIALIZER;
127
128 /*!
129  @abstract Convenience getter to determine if a permission has been granted
130  @param permission  The permission to check.
131  */
132 - (BOOL)hasGranted:(NSString *)permission;
133
134 /*!
135  @abstract Compares the receiver to another FBSDKAccessToken
136  @param token The other token
137  @return YES if the receiver's values are equal to the other token's values; otherwise NO
138  */
139 - (BOOL)isEqualToAccessToken:(FBSDKAccessToken *)token;
140
141 /*!
142  @abstract Returns the "global" access token that represents the currently logged in user.
143  @discussion The `currentAccessToken` is a convenient representation of the token of the
144  current user and is used by other SDK components (like `FBSDKLoginManager`).
145  */
146 + (FBSDKAccessToken *)currentAccessToken;
147
148 /*!
149  @abstract Sets the "global" access token that represents the currently logged in user.
150  @param token The access token to set.
151  @discussion This will broadcast a notification and save the token to the app keychain.
152  */
153 + (void)setCurrentAccessToken:(FBSDKAccessToken *)token;
154
155 /*!
156  @abstract Refresh the current access token's permission state and extend the token's expiration date,
157   if possible.
158  @param completionHandler an optional callback handler that can surface any errors related to permission refreshing.
159  @discussion On a successful refresh, the currentAccessToken will be updated so you typically only need to
160   observe the `FBSDKAccessTokenDidChangeNotification` notification.
161
162  If a token is already expired, it cannot be refreshed.
163  */
164 + (void)refreshCurrentAccessToken:(FBSDKGraphRequestHandler)completionHandler;
165
166 @end