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 <UIKit/UIKit.h> |
|
20 |
|
b19a78
|
21 |
#import "FBSDKLoginConfiguration.h" |
L |
22 |
|
e81c27
|
23 |
NS_ASSUME_NONNULL_BEGIN |
49b883
|
24 |
|
L |
25 |
#if TARGET_OS_TV |
|
26 |
|
|
27 |
// This is an unfortunate hack for Swift Package Manager support. |
|
28 |
// SPM does not allow us to conditionally exclude Swift files for compilation by platform. |
|
29 |
// |
|
30 |
// So to support tvOS with SPM we need to use runtime availability checks in the Swift files. |
|
31 |
// This means that even though the code in `LoginManager.swift` will never be run for tvOS |
|
32 |
// targets, it still needs to be able to compile. Hence we need to declare it here. |
|
33 |
// |
|
34 |
// The way to fix this is to remove extensions of ObjC types in Swift. |
|
35 |
|
|
36 |
@class LoginManagerLoginResult; |
b19a78
|
37 |
@class FBSDKLoginConfiguration; |
49b883
|
38 |
|
L |
39 |
typedef NS_ENUM(NSUInteger, LoginBehavior) { LoginBehaviorBrowser }; |
|
40 |
typedef NS_ENUM(NSUInteger, DefaultAudience) { DefaultAudienceFriends }; |
b19a78
|
41 |
|
49b883
|
42 |
typedef void (^LoginManagerLoginResultBlock)(LoginManagerLoginResult *_Nullable result, |
L |
43 |
NSError *_Nullable error); |
|
44 |
|
|
45 |
@interface LoginManager : NSObject |
|
46 |
|
|
47 |
@property (assign, nonatomic) LoginBehavior loginBehavior; |
|
48 |
@property (assign, nonatomic) DefaultAudience defaultAudience; |
|
49 |
|
|
50 |
- (void)logInWithPermissions:(NSArray<NSString *> *)permissions |
|
51 |
fromViewController:(nullable UIViewController *)fromViewController |
|
52 |
handler:(nullable LoginManagerLoginResultBlock)handler |
|
53 |
NS_SWIFT_NAME(logIn(permissions:from:handler:)); |
b19a78
|
54 |
|
L |
55 |
- (void)logInFromViewController:(nullable UIViewController *)viewController |
|
56 |
configuration:(FBSDKLoginConfiguration *)configuration |
|
57 |
completion:(LoginManagerLoginResultBlock)completion |
|
58 |
NS_REFINED_FOR_SWIFT; |
49b883
|
59 |
|
L |
60 |
@end |
|
61 |
|
|
62 |
#else |
e81c27
|
63 |
|
bad748
|
64 |
@class FBSDKLoginManagerLoginResult; |
e81c27
|
65 |
|
H |
66 |
/// typedef for FBSDKLoginAuthType |
|
67 |
typedef NSString *const FBSDKLoginAuthType NS_TYPED_EXTENSIBLE_ENUM NS_SWIFT_NAME(LoginAuthType); |
|
68 |
|
|
69 |
/// Rerequest |
|
70 |
FOUNDATION_EXPORT FBSDKLoginAuthType FBSDKLoginAuthTypeRerequest; |
|
71 |
|
|
72 |
/// Reauthorize |
|
73 |
FOUNDATION_EXPORT FBSDKLoginAuthType FBSDKLoginAuthTypeReauthorize; |
bad748
|
74 |
|
9febd9
|
75 |
/** |
W |
76 |
Describes the call back to the FBSDKLoginManager |
13e53a
|
77 |
@param result the result of the authorization |
H |
78 |
@param error the authorization error, if any. |
bad748
|
79 |
*/ |
e81c27
|
80 |
typedef void (^FBSDKLoginManagerLoginResultBlock)(FBSDKLoginManagerLoginResult *_Nullable result, |
H |
81 |
NSError *_Nullable error) |
|
82 |
NS_SWIFT_NAME(LoginManagerLoginResultBlock); |
bad748
|
83 |
|
W |
84 |
|
9febd9
|
85 |
/** |
W |
86 |
FBSDKDefaultAudience enum |
bad748
|
87 |
|
b19a78
|
88 |
Passed to openURL to indicate which default audience to use for sessions that post data to Facebook. |
9febd9
|
89 |
|
bad748
|
90 |
Certain operations such as publishing a status or publishing a photo require an audience. When the user |
W |
91 |
grants an application permission to perform a publish operation, a default audience is selected as the |
|
92 |
publication ceiling for the application. This enumerated value allows the application to select which |
|
93 |
audience to ask the user to grant publish permission for. |
|
94 |
*/ |
|
95 |
typedef NS_ENUM(NSUInteger, FBSDKDefaultAudience) |
|
96 |
{ |
9febd9
|
97 |
/** Indicates that the user's friends are able to see posts made by the application */ |
bad748
|
98 |
FBSDKDefaultAudienceFriends = 0, |
9febd9
|
99 |
/** Indicates that only the user is able to see posts made by the application */ |
bad748
|
100 |
FBSDKDefaultAudienceOnlyMe, |
9febd9
|
101 |
/** Indicates that all Facebook users are able to see posts made by the application */ |
bad748
|
102 |
FBSDKDefaultAudienceEveryone, |
e81c27
|
103 |
} NS_SWIFT_NAME(DefaultAudience); |
bad748
|
104 |
|
9febd9
|
105 |
/** |
W |
106 |
`FBSDKLoginManager` provides methods for logging the user in and out. |
|
107 |
|
b19a78
|
108 |
`FBSDKLoginManager` serves to help manage sessions represented by tokens for authentication, |
L |
109 |
`AuthenticationToken`, and data access, `AccessToken`. |
bad748
|
110 |
|
b19a78
|
111 |
You should check if the type of token you expect is present as a singleton instance, either `AccessToken.current` |
L |
112 |
or `AuthenticationToken.current` before calling any of the login methods to see if there is a cached token |
|
113 |
available. A standard place to do this is in `viewDidLoad`. |
bad748
|
114 |
|
b19a78
|
115 |
@warning If you are managing your own token instances outside of `AccessToken.current`, you will need to set |
L |
116 |
`AccessToken.current` before calling any of the login methods to authorize further permissions on your tokens. |
bad748
|
117 |
*/ |
e81c27
|
118 |
NS_SWIFT_NAME(LoginManager) |
bad748
|
119 |
@interface FBSDKLoginManager : NSObject |
W |
120 |
|
9febd9
|
121 |
/** |
9f077b
|
122 |
Auth type |
H |
123 |
*/ |
e81c27
|
124 |
@property (strong, nonatomic) FBSDKLoginAuthType authType; |
9f077b
|
125 |
/** |
9febd9
|
126 |
the default audience. |
W |
127 |
|
|
128 |
you should set this if you intend to ask for publish permissions. |
bad748
|
129 |
*/ |
W |
130 |
@property (assign, nonatomic) FBSDKDefaultAudience defaultAudience; |
|
131 |
|
9febd9
|
132 |
/** |
e81c27
|
133 |
Logs the user in or authorizes additional permissions. |
b19a78
|
134 |
|
13e53a
|
135 |
@param permissions the optional array of permissions. Note this is converted to NSSet and is only |
bad748
|
136 |
an NSArray for the convenience of literal syntax. |
13e53a
|
137 |
@param fromViewController the view controller to present from. If nil, the topmost view controller will be |
bad748
|
138 |
automatically determined as best as possible. |
13e53a
|
139 |
@param handler the callback. |
9febd9
|
140 |
|
e81c27
|
141 |
Use this method when asking for read permissions. You should only ask for permissions when they |
b19a78
|
142 |
are needed and explain the value to the user. You can inspect the `FBSDKLoginManagerLoginResultBlock`'s |
L |
143 |
`result.declinedPermissions` to provide more information to the user if they decline permissions. |
|
144 |
You typically should check if `AccessToken.current` already contains the permissions you need before |
|
145 |
asking to reduce unnecessary login attempts. For example, you could perform that check in `viewDidLoad`. |
bad748
|
146 |
|
b19a78
|
147 |
@warning You can only perform one login call at a time. Calling a login method before the completion handler is called |
L |
148 |
on a previous login attempt will result in an error. |
|
149 |
@warning This method will present a UI to the user and thus should be called on the main thread. |
bad748
|
150 |
*/ |
e81c27
|
151 |
- (void)logInWithPermissions:(NSArray<NSString *> *)permissions |
b19a78
|
152 |
fromViewController:(nullable UIViewController *)fromViewController |
L |
153 |
handler:(nullable FBSDKLoginManagerLoginResultBlock)handler |
e81c27
|
154 |
NS_SWIFT_NAME(logIn(permissions:from:handler:)); |
b19a78
|
155 |
|
L |
156 |
/** |
|
157 |
Logs the user in or authorizes additional permissions. |
|
158 |
|
|
159 |
@param viewController the view controller from which to present the login UI. If nil, the topmost view |
|
160 |
controller will be automatically determined and used. |
|
161 |
@param configuration the login configuration to use. |
|
162 |
@param completion the login completion handler. |
|
163 |
|
|
164 |
Use this method when asking for permissions. You should only ask for permissions when they |
|
165 |
are needed and the value should be explained to the user. You can inspect the |
|
166 |
`FBSDKLoginManagerLoginResultBlock`'s `result.declinedPermissions` to provide more information |
|
167 |
to the user if they decline permissions. |
|
168 |
To reduce unnecessary login attempts, you should typically check if `AccessToken.current` |
|
169 |
already contains the permissions you need. If it does, you probably do not need to call this method. |
|
170 |
|
|
171 |
@warning You can only perform one login call at a time. Calling a login method before the completion handler is called |
|
172 |
on a previous login attempt will result in an error. |
|
173 |
@warning This method will present a UI to the user and thus should be called on the main thread. |
|
174 |
*/ |
|
175 |
- (void)logInFromViewController:(nullable UIViewController *)viewController |
|
176 |
configuration:(FBSDKLoginConfiguration *)configuration |
|
177 |
completion:(FBSDKLoginManagerLoginResultBlock)completion |
|
178 |
NS_REFINED_FOR_SWIFT; |
49b883
|
179 |
|
L |
180 |
/** |
|
181 |
Logs the user in with the given deep link url. Will only log user in if the given url contains valid login data. |
|
182 |
@param url the deep link url |
|
183 |
@param handler the callback. |
|
184 |
|
b19a78
|
185 |
This method will present a UI to the user and thus should be called on the main thread. |
L |
186 |
This method should be called with the url from the openURL method. |
|
187 |
|
|
188 |
@warning This method will present a UI to the user and thus should be called on the main thread. |
49b883
|
189 |
*/ |
L |
190 |
- (void)logInWithURL:(NSURL *)url |
|
191 |
handler:(nullable FBSDKLoginManagerLoginResultBlock)handler |
|
192 |
NS_SWIFT_NAME(logIn(url:handler:)); |
13e53a
|
193 |
|
H |
194 |
/** |
b19a78
|
195 |
Requests user's permission to reathorize application's data access, after it has expired due to inactivity. |
L |
196 |
@param fromViewController the view controller from which to present the login UI. If nil, the topmost view |
|
197 |
controller will be automatically determined and used. |
13e53a
|
198 |
@param handler the callback. |
b19a78
|
199 |
|
L |
200 |
Use this method when you need to reathorize your app's access to user data via the Graph API. |
|
201 |
You should only call this after access has expired. |
|
202 |
You should provide as much context to the user as possible as to why you need to reauthorize the access, the |
|
203 |
scope of access being reathorized, and what added value your app provides when the access is reathorized. |
|
204 |
You can inspect the `result.declinedPermissions` to determine if you should provide more information to the |
|
205 |
user based on any declined permissions. |
|
206 |
|
|
207 |
@warning This method will reauthorize using a `LoginConfiguration` with `FBSDKLoginTracking` set to `.enabled`. |
|
208 |
@warning This method will present UI the user. You typically should call this if `AccessToken.isDataAccessExpired` is true. |
13e53a
|
209 |
*/ |
H |
210 |
- (void)reauthorizeDataAccess:(UIViewController *)fromViewController |
e81c27
|
211 |
handler:(FBSDKLoginManagerLoginResultBlock)handler |
H |
212 |
NS_SWIFT_NAME(reauthorizeDataAccess(from:handler:)); |
13e53a
|
213 |
|
9febd9
|
214 |
/** |
W |
215 |
Logs the user out |
|
216 |
|
b19a78
|
217 |
This nils out the singleton instances of `AccessToken` `AuthenticationToken` and `Profle`. |
L |
218 |
|
|
219 |
@note This is only a client side logout. It will not log the user out of their Facebook account. |
bad748
|
220 |
*/ |
W |
221 |
- (void)logOut; |
|
222 |
|
|
223 |
@end |
e81c27
|
224 |
|
49b883
|
225 |
#endif |
L |
226 |
|
e81c27
|
227 |
NS_ASSUME_NONNULL_END |