FBSDKLoginManager.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  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. #import <Accounts/Accounts.h>
  19. #import <Foundation/Foundation.h>
  20. #import <UIKit/UIKit.h>
  21. @class FBSDKLoginManagerLoginResult;
  22. /**
  23. Describes the call back to the FBSDKLoginManager
  24. @param result the result of the authorization
  25. @param error the authorization error, if any.
  26. */
  27. typedef void (^FBSDKLoginManagerRequestTokenHandler)(FBSDKLoginManagerLoginResult *result, NSError *error);
  28. /**
  29. FBSDKDefaultAudience enum
  30. Passed to open to indicate which default audience to use for sessions that post data to Facebook.
  31. Certain operations such as publishing a status or publishing a photo require an audience. When the user
  32. grants an application permission to perform a publish operation, a default audience is selected as the
  33. publication ceiling for the application. This enumerated value allows the application to select which
  34. audience to ask the user to grant publish permission for.
  35. */
  36. typedef NS_ENUM(NSUInteger, FBSDKDefaultAudience)
  37. {
  38. /** Indicates that the user's friends are able to see posts made by the application */
  39. FBSDKDefaultAudienceFriends = 0,
  40. /** Indicates that only the user is able to see posts made by the application */
  41. FBSDKDefaultAudienceOnlyMe,
  42. /** Indicates that all Facebook users are able to see posts made by the application */
  43. FBSDKDefaultAudienceEveryone,
  44. };
  45. /**
  46. FBSDKLoginBehavior enum
  47. Passed to the \c FBSDKLoginManager to indicate how Facebook Login should be attempted.
  48. Facebook Login authorizes the application to act on behalf of the user, using the user's
  49. Facebook account. Usually a Facebook Login will rely on an account maintained outside of
  50. the application, by the native Facebook application, the browser, or perhaps the device
  51. itself. This avoids the need for a user to enter their username and password directly, and
  52. provides the most secure and lowest friction way for a user to authorize the application to
  53. interact with Facebook.
  54. The \c FBSDKLoginBehavior enum specifies which log-in methods may be used. The SDK
  55. will determine the best behavior based on the current device (such as iOS version).
  56. */
  57. typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
  58. {
  59. /**
  60. This is the default behavior, and indicates logging in through the native
  61. Facebook app may be used. The SDK may still use Safari instead.
  62. */
  63. FBSDKLoginBehaviorNative = 0,
  64. /**
  65. Attempts log in through the Safari or SFSafariViewController, if available.
  66. */
  67. FBSDKLoginBehaviorBrowser,
  68. /**
  69. Attempts log in through the Facebook account currently signed in through
  70. the device Settings.
  71. @note If the account is not available to the app (either not configured by user or
  72. as determined by the SDK) this behavior falls back to \c FBSDKLoginBehaviorNative.
  73. */
  74. FBSDKLoginBehaviorSystemAccount,
  75. /**
  76. Attempts log in through a modal \c UIWebView pop up
  77. @note This behavior is only available to certain types of apps. Please check the Facebook
  78. Platform Policy to verify your app meets the restrictions.
  79. */
  80. FBSDKLoginBehaviorWeb,
  81. };
  82. /**
  83. `FBSDKLoginManager` provides methods for logging the user in and out.
  84. `FBSDKLoginManager` works directly with `[FBSDKAccessToken currentAccessToken]` and
  85. sets the "currentAccessToken" upon successful authorizations (or sets `nil` in case of `logOut`).
  86. You should check `[FBSDKAccessToken currentAccessToken]` before calling logIn* to see if there is
  87. a cached token available (typically in your viewDidLoad).
  88. If you are managing your own token instances outside of "currentAccessToken", you will need to set
  89. "currentAccessToken" before calling logIn* to authorize further permissions on your tokens.
  90. */
  91. @interface FBSDKLoginManager : NSObject
  92. /**
  93. Auth type
  94. */
  95. @property (strong, nonatomic) NSString *authType;
  96. /**
  97. the default audience.
  98. you should set this if you intend to ask for publish permissions.
  99. */
  100. @property (assign, nonatomic) FBSDKDefaultAudience defaultAudience;
  101. /**
  102. the login behavior
  103. */
  104. @property (assign, nonatomic) FBSDKLoginBehavior loginBehavior;
  105. /**
  106. @warning use logInWithReadPermissions:fromViewController:handler: instead
  107. */
  108. - (void)logInWithReadPermissions:(NSArray *)permissions handler:(FBSDKLoginManagerRequestTokenHandler)handler
  109. DEPRECATED_MSG_ATTRIBUTE("use logInWithReadPermissions:fromViewController:handler: instead");
  110. /**
  111. @warning use logInWithPublishPermissions:fromViewController:handler: instead
  112. */
  113. - (void)logInWithPublishPermissions:(NSArray *)permissions handler:(FBSDKLoginManagerRequestTokenHandler)handler
  114. DEPRECATED_MSG_ATTRIBUTE("use logInWithPublishPermissions:fromViewController:handler: instead");
  115. /**
  116. Logs the user in or authorizes additional permissions.
  117. @param permissions the optional array of permissions. Note this is converted to NSSet and is only
  118. an NSArray for the convenience of literal syntax.
  119. @param fromViewController the view controller to present from. If nil, the topmost view controller will be
  120. automatically determined as best as possible.
  121. @param handler the callback.
  122. Use this method when asking for read permissions. You should only ask for permissions when they
  123. are needed and explain the value to the user. You can inspect the result.declinedPermissions to also
  124. provide more information to the user if they decline permissions.
  125. This method will present UI the user. You typically should check if `[FBSDKAccessToken currentAccessToken]`
  126. already contains the permissions you need before asking to reduce unnecessary app switching. For example,
  127. you could make that check at viewDidLoad.
  128. You can only do one login call at a time. Calling a login method before the completion handler is called
  129. on a previous login will return an error.
  130. */
  131. - (void)logInWithReadPermissions:(NSArray *)permissions
  132. fromViewController:(UIViewController *)fromViewController
  133. handler:(FBSDKLoginManagerRequestTokenHandler)handler;
  134. /**
  135. Logs the user in or authorizes additional permissions.
  136. @param permissions the optional array of permissions. Note this is converted to NSSet and is only
  137. an NSArray for the convenience of literal syntax.
  138. @param fromViewController the view controller to present from. If nil, the topmost view controller will be
  139. automatically determined as best as possible.
  140. @param handler the callback.
  141. Use this method when asking for publish permissions. You should only ask for permissions when they
  142. are needed and explain the value to the user. You can inspect the result.declinedPermissions to also
  143. provide more information to the user if they decline permissions.
  144. This method will present UI the user. You typically should check if `[FBSDKAccessToken currentAccessToken]`
  145. already contains the permissions you need before asking to reduce unnecessary app switching. For example,
  146. you could make that check at viewDidLoad.
  147. You can only do one login call at a time. Calling a login method before the completion handler is called
  148. on a previous login will return an error.
  149. */
  150. - (void)logInWithPublishPermissions:(NSArray *)permissions
  151. fromViewController:(UIViewController *)fromViewController
  152. handler:(FBSDKLoginManagerRequestTokenHandler)handler;
  153. /**
  154. Requests user's permission to reathorize application's data access, after it has expired due to inactivity.
  155. @param fromViewController the view controller to present from. If nil, the topmost view controller will be
  156. automatically determined as best as possible.
  157. @param handler the callback.
  158. Use this method when you need to reathorize your app's access to user data via Graph API, after such an access has expired.
  159. You should provide as much context to the user as possible as to why you need to reauthorize the access, the scope of
  160. access being reathorized, and what added value your app provides when the access is reathorized.
  161. You can inspect the result.declinedPermissions to also provide more information to the user if they decline permissions.
  162. This method will present UI the user. You typically should call this if `[FBSDKAccessToken isDataAccessExpired]` returns true.
  163. */
  164. - (void)reauthorizeDataAccess:(UIViewController *)fromViewController
  165. handler:(FBSDKLoginManagerRequestTokenHandler)handler;
  166. /**
  167. Logs the user out
  168. This calls [FBSDKAccessToken setCurrentAccessToken:nil] and [FBSDKProfile setCurrentProfile:nil].
  169. */
  170. - (void)logOut;
  171. /**
  172. @method
  173. Issues an asynchronous renewCredentialsForAccount call to the device's Facebook account store.
  174. @param handler The completion handler to call when the renewal is completed. This can be invoked on an arbitrary thread.
  175. This can be used to explicitly renew account credentials and is provided as a convenience wrapper around
  176. `[ACAccountStore renewCredentialsForAccount:completion]`. Note the method will not issue the renewal call if the the
  177. Facebook account has not been set on the device, or if access had not been granted to the account (though the handler
  178. wil receive an error).
  179. If the `[FBSDKAccessToken currentAccessToken]` was from the account store, a succesful renewal will also set
  180. a new "currentAccessToken".
  181. */
  182. + (void)renewSystemCredentials:(void (^)(ACAccountCredentialRenewResult result, NSError *error))handler;
  183. @end