/
SKYAuthContainer.h
329 lines (271 loc) · 11.2 KB
/
SKYAuthContainer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
//
// SKYAuthContainer.h
// SKYKit
//
// Copyright 2015 Oursky Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import "SKYAccessToken.h"
#import "SKYAuthResponseDelegateProtocol.h"
#import "SKYDatabase.h"
NS_ASSUME_NONNULL_BEGIN
/// Undocumented
@class SKYContainer;
// keep it in sync with SKYUserOperationActionCompletion
/// Undocumented
typedef void (^SKYContainerUserOperationActionCompletion)(SKYRecord *_Nullable user,
NSError *_Nullable error);
@interface SKYAuthContainer : NSObject <SKYAuthResponseDelegateProtocol>
/// Undocumented
@property (nonatomic, readonly) NSString *_Nullable currentUserRecordID;
/// Undocumented
@property (nonatomic, readonly) SKYAccessToken *_Nullable currentAccessToken;
/// Undocumented
@property (nonatomic, readonly) SKYRecord *_Nullable currentUser;
/// Undocumented
@property (nonatomic, readonly) BOOL currentUserVerified;
/**
Set current user data encryption enable state
When this is on, current user data will be saved and retrieved from Keychain instead of
UserDefaults. Default is NO.
*/
- (void)setCurrentUserDataEncryptionEnable:(BOOL)enabled;
/**
Updates the <currentUserRecordID> and <currentAccessToken>. The updated access credentials are also
stored in persistent
storage.
This method is called when operation sign up, log in and log out is performed using the container's
convenient
method and when the operation is completed successfully.
*/
- (void)updateWithUserRecordID:(NSString *_Nullable)userRecordID
accessToken:(SKYAccessToken *_Nullable)accessToken;
/**
Updates the <currentUser> and <currentAccessToken>. The updated access credentials are also
stored in persistent storage.
This method is called when operation sign up, log in and log out is performed using the container's
convenient
method and when the operation is completed successfully.
*/
- (void)updateWithUser:(SKYRecord *_Nullable)user
accessToken:(SKYAccessToken *_Nullable)accessToken;
/**
Set the handler to be called when SKYOperation's subclasses failed to authenticate itself with
remote server.
Such circumstance might arise on a container when either:
1. There are no logged-in users for an opertion that requires users login.
2. Access token is invalid or has been expired.
In either cases, developer should prompt for re-authentication of user and login using
<SKYLoginUserOperation>.
NOTE: Any attempt to invoke user logout related operation within the set handler will created an
feedback loop as logouting an invalid access token is also a kind of authentication error.
*/
- (void)setAuthenticationErrorHandler:(void (^_Nullable)(SKYContainer *container,
SKYAccessToken *_Nullable token,
NSError *_Nullable error))authErrorHandler;
@end
@interface SKYAuthContainer (Signup)
/**
Creates an anonymous user account and log in as the created user.
Use this to create a user that is not associated with an email address. This is a convenient method
for
<SKYSignupUserOperation>.
*/
- (void)signupAnonymouslyWithCompletionHandler:
(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Creates a user account with the specified auth data and password.
*/
- (void)signupWithAuthData:(NSDictionary *)authData
password:(NSString *)password
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Creates a user account with the specified auth data, password and profile.
*/
- (void)signupWithAuthData:(NSDictionary *)authData
password:(NSString *)password
profileDictionary:(NSDictionary *_Nullable)profile
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Creates a user account with the specified username and password.
*/
- (void)signupWithUsername:(NSString *)username
password:(NSString *)password
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Creates a user account with the specified email and password.
*/
- (void)signupWithEmail:(NSString *)email
password:(NSString *)password
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Creates a user account with the specified username, password and profile.
*/
- (void)signupWithUsername:(NSString *)username
password:(NSString *)password
profileDictionary:(NSDictionary *_Nullable)profile
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Creates a user account with the specified email, password and profile.
*/
- (void)signupWithEmail:(NSString *)email
password:(NSString *)password
profileDictionary:(NSDictionary *_Nullable)profile
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
@end
@interface SKYAuthContainer (Login)
/**
Logs in to an existing user account with the specified auth data and password.
*/
- (void)loginWithAuthData:(NSDictionary *)authData
password:(NSString *)password
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Logs in to an existing user account with the specified username and password.
*/
- (void)loginWithUsername:(NSString *)username
password:(NSString *)password
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Logs in to an existing user account with the specified email and password.
*/
- (void)loginWithEmail:(NSString *)email
password:(NSString *)password
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
/**
Logs out the current user of this container.
This is a convenient method for <SKYLogoutUserOperation>.
*/
- (void)logoutWithCompletionHandler:
(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
@end
@interface SKYAuthContainer (ChangePasswordMethods)
/**
Changes the password of the current user of this container.
This is a convenient method for <SKYChangePasswordOperation>.
*/
- (void)setNewPassword:(NSString *)newPassword
oldPassword:(NSString *)oldPassword
completionHandler:(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
@end
@interface SKYAuthContainer (UserDiscovery)
/**
* Asks "Who am I" to server.
*
* @param completionHandler the completion handler
*/
- (void)getWhoAmIWithCompletionHandler:
(SKYContainerUserOperationActionCompletion _Nullable)completionHandler;
@end
@interface SKYAuthContainer (UserRole)
/**
* Defines roles to have special powers
*/
- (void)defineAdminRoles:(NSArray<SKYRole *> *)roles
completion:(void (^_Nullable)(NSError *_Nullable error))completionBlock;
/**
* Sets default roles for new registered users
*/
- (void)setUserDefaultRole:(NSArray<SKYRole *> *)roles
completion:(void (^_Nullable)(NSError *_Nullable error))completionBlock;
/**
* Get roles of users
*
* @param users Target users
* @param completionBlock Completion Block, with a user-to-roles dictionary
*/
- (void)fetchRolesOfUsers:(NSArray<SKYRecord *> *)users
completion:(void (^_Nullable)(
NSDictionary<NSString *, NSArray<SKYRole *> *> *_Nullable userRoles,
NSError *_Nullable error))completionBlock;
/**
* Get roles of users
*
* @param userIDs Target user
* @param completionBlock Completion Block, with a user-to-roles dictionary
*/
- (void)fetchRolesOfUsersWithUserIDs:(NSArray<NSString *> *)userIDs
completion:
(void (^_Nullable)(NSDictionary<NSString *, NSArray<NSString *> *>
*_Nullable userRoles,
NSError *_Nullable error))completionBlock;
/**
* Assign roles to users
*
* @param roles Roles to be assigned
* @param users Target users
* @param completionBlock Completion Block
*/
- (void)assignRoles:(NSArray<SKYRole *> *)roles
toUsers:(NSArray<SKYRecord *> *)users
completion:(void (^_Nullable)(NSError *_Nullable error))completionBlock;
/**
* Assign roles to users
*
* @param roleNames Roles to be assigned
* @param userIDs Target users
* @param completionBlock Completion Block
*/
- (void)assignRolesWithNames:(NSArray<NSString *> *)roleNames
toUsersWithIDs:(NSArray<NSString *> *)userIDs
completion:(void (^_Nullable)(NSError *_Nullable error))completionBlock;
/**
* Revoke roles from users
*
* @param roles Roles to be revoked
* @param users Target users
* @param completionBlock Completion Block
*/
- (void)revokeRoles:(NSArray<SKYRole *> *)roles
fromUsers:(NSArray<SKYRecord *> *)users
completion:(void (^_Nullable)(NSError *_Nullable error))completionBlock;
/**
* Revoke roles from users
*
* @param roleNames Roles to be revoked
* @param userIDs Target users
* @param completionBlock Completion Block
*/
- (void)revokeRolesWithNames:(NSArray<NSString *> *)roleNames
fromUsersWihtIDs:(NSArray<NSString *> *)userIDs
completion:(void (^_Nullable)(NSError *_Nullable error))completionBlock;
@end
@interface SKYAuthContainer (UserDisable)
/**
* Enable user account of a disabled user.
*
* @param userID User ID of a disabled user
* @param completionBlock Completion Block
*/
- (void)adminEnableUserWithUserID:(NSString *)userID
completion:(void (^_Nullable)(NSString *userID,
NSError *_Nullable error))completionBlock;
/**
* Disable user account of a user.
*
* @param userID User ID of user to disable
* @param message Message to be shown to user, to explain why the account is disabled,
* optional
* @param expiry Date and time when the disable user account is automatically enabled,
* optional
* @param completionBlock Completion Block
*/
- (void)adminDisableUserWithUserID:(NSString *)userID
message:(NSString *_Nullable)message
expiry:(NSDate *_Nullable)expiry
completion:(void (^_Nullable)(NSString *userID,
NSError *_Nullable error))completionBlock;
@end
NS_ASSUME_NONNULL_END