FBAccessTokenData.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright 2010-present Facebook.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "FBSession.h"
  18. /*!
  19. @class FBAccessTokenData
  20. @abstract Represents an access token used for the Facebook login flow
  21. and includes associated metadata such as expiration date and permissions.
  22. You should use factory methods (createToken...) to construct instances
  23. and should be treated as immutable.
  24. @discussion For more information, see
  25. https://developers.facebook.com/docs/concepts/login/access-tokens-and-types/.
  26. */
  27. @interface FBAccessTokenData : NSObject <NSCopying>
  28. /*!
  29. @method
  30. @abstract Creates an FBAccessTokenData from an App Link provided by the Facebook application
  31. or nil if the url is not valid.
  32. @param url The url provided.
  33. @param appID needed in order to verify URL format.
  34. @param urlSchemeSuffix needed in order to verify URL format.
  35. */
  36. + (FBAccessTokenData *)createTokenFromFacebookURL:(NSURL *)url appID:(NSString *)appID urlSchemeSuffix:(NSString *)urlSchemeSuffix;
  37. /*!
  38. @method
  39. @abstract Creates an FBAccessTokenData from a dictionary or returns nil if required data is missing.
  40. @param dictionary the dictionary with FBSessionTokenCachingStrategy keys.
  41. */
  42. + (FBAccessTokenData *)createTokenFromDictionary:(NSDictionary *)dictionary;
  43. /*!
  44. @method
  45. @abstract Creates an FBAccessTokenData from existing information or returns nil if required data is missing.
  46. @param accessToken The token string. If nil or empty, this method will return nil.
  47. @param permissions The permissions set. A value of nil indicates basic permissions.
  48. @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`.
  49. @param loginType The login source of the token.
  50. @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`.
  51. */
  52. + (FBAccessTokenData *)createTokenFromString:(NSString *)accessToken
  53. permissions:(NSArray *)permissions
  54. expirationDate:(NSDate *)expirationDate
  55. loginType:(FBSessionLoginType)loginType
  56. refreshDate:(NSDate *)refreshDate;
  57. /*!
  58. @method
  59. @abstract Creates an FBAccessTokenData from existing information or returns nil if required data is missing.
  60. @param accessToken The token string. If nil or empty, this method will return nil.
  61. @param permissions The permissions set. A value of nil indicates basic permissions.
  62. @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`.
  63. @param loginType The login source of the token.
  64. @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`.
  65. @param permissionsRefreshDate The date the permissions were last refreshed. A value of nil defaults to `[NSDate distantPast]`.
  66. */
  67. + (FBAccessTokenData *)createTokenFromString:(NSString *)accessToken
  68. permissions:(NSArray *)permissions
  69. expirationDate:(NSDate *)expirationDate
  70. loginType:(FBSessionLoginType)loginType
  71. refreshDate:(NSDate *)refreshDate
  72. permissionsRefreshDate:(NSDate *)permissionsRefreshDate;
  73. /*!
  74. @method
  75. @abstract Creates an FBAccessTokenData from existing information or returns nil if required data is missing.
  76. @param accessToken The token string. If nil or empty, this method will return nil.
  77. @param permissions The permissions set. A value of nil indicates basic permissions.
  78. @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`.
  79. @param loginType The login source of the token.
  80. @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`.
  81. @param permissionsRefreshDate The date the permissions were last refreshed. A value of nil defaults to `[NSDate distantPast]`.
  82. @param appID The ID string of the calling app. A value of nil defaults to `[FBSettings defaultAppID]`.
  83. */
  84. + (FBAccessTokenData *)createTokenFromString:(NSString *)accessToken
  85. permissions:(NSArray *)permissions
  86. expirationDate:(NSDate *)expirationDate
  87. loginType:(FBSessionLoginType)loginType
  88. refreshDate:(NSDate *)refreshDate
  89. permissionsRefreshDate:(NSDate *)permissionsRefreshDate
  90. appID:(NSString *)appID;
  91. /*!
  92. @method
  93. @abstract Designated factory method.
  94. Creates an FBAccessTokenData from existing information or returns nil if required data is missing.
  95. @param accessToken The token string. If nil or empty, this method will return nil.
  96. @param permissions The permissions set. A value of nil indicates basic permissions.
  97. @param declinedPermissions The declined permissions set. A value of nil indicates empty array.
  98. @param expirationDate The expiration date. A value of nil defaults to `[NSDate distantFuture]`.
  99. @param loginType The login source of the token.
  100. @param refreshDate The date that token was last refreshed. A value of nil defaults to `[NSDate date]`.
  101. @param permissionsRefreshDate The date the permissions were last refreshed. A value of nil defaults to `[NSDate distantPast]`.
  102. @param appID The ID string of the calling app. A value of nil defaults to `[FBSettings defaultAppID]`.
  103. */
  104. + (FBAccessTokenData *)createTokenFromString:(NSString *)accessToken
  105. permissions:(NSArray *)permissions
  106. declinedPermissions:(NSArray *)declinedPermissions
  107. expirationDate:(NSDate *)expirationDate
  108. loginType:(FBSessionLoginType)loginType
  109. refreshDate:(NSDate *)refreshDate
  110. permissionsRefreshDate:(NSDate *)permissionsRefreshDate
  111. appID:(NSString *)appID
  112. userID:(NSString *)userID;
  113. /*!
  114. @method
  115. @abstract Returns a dictionary representation of this instance.
  116. @discussion This is provided for backwards compatibility with previous
  117. access token related APIs that used a NSDictionary (see `FBSessionTokenCachingStrategy`).
  118. */
  119. - (NSMutableDictionary *)dictionary;
  120. /*!
  121. @method
  122. @abstract Returns a Boolean value that indicates whether a given object is an FBAccessTokenData object and exactly equal the receiver.
  123. @param accessTokenData the data to compare to the receiver.
  124. */
  125. - (BOOL)isEqualToAccessTokenData:(FBAccessTokenData *)accessTokenData;
  126. /*!
  127. @abstract returns the access token NSString.
  128. */
  129. @property (readonly, nonatomic, copy) NSString *accessToken;
  130. /*!
  131. @abstract returns the app ID NSString.
  132. */
  133. @property (readonly, nonatomic, copy) NSString *appID;
  134. /*!
  135. @abstract returns the user ID NSString that is associated with the token,if available.
  136. @discussion This may not be populated for login behaviours such as the iOS system account.
  137. */
  138. @property (readonly, nonatomic, copy) NSString *userID;
  139. /*!
  140. @abstract returns the permissions associated with the access token.
  141. */
  142. @property (readonly, nonatomic, copy) NSArray *permissions;
  143. /*!
  144. @abstract returns the declined permissions associated with the access token.
  145. */
  146. @property (readonly, nonatomic, copy) NSArray *declinedPermissions;
  147. /*!
  148. @abstract returns the expiration date of the access token.
  149. */
  150. @property (readonly, nonatomic, copy) NSDate *expirationDate;
  151. /*!
  152. @abstract returns the login type associated with the token.
  153. */
  154. @property (readonly, nonatomic) FBSessionLoginType loginType;
  155. /*!
  156. @abstract returns the date the token was last refreshed.
  157. */
  158. @property (readonly, nonatomic, copy) NSDate *refreshDate;
  159. /*!
  160. @abstract returns the date the permissions were last refreshed.
  161. */
  162. @property (readonly, nonatomic, copy) NSDate *permissionsRefreshDate;
  163. @end