This repository was archived by the owner on Feb 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathBITAuthenticator.h
More file actions
385 lines (343 loc) · 14.2 KB
/
Copy pathBITAuthenticator.h
File metadata and controls
385 lines (343 loc) · 14.2 KB
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*
* Author: Stephan Diederich, Andreas Linde
*
* Copyright (c) 2013-2014 HockeyApp, Bit Stadium GmbH.
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import "BITHockeyBaseManager.h"
/**
* Identification Types
*/
typedef NS_ENUM(NSUInteger, BITAuthenticatorIdentificationType) {
/**
* Assigns this app an anonymous user id.
* <br/><br/>
* The user will not be asked anything and an anonymous ID will be generated.
* This helps identifying this installation being unique but HockeyApp won't be able
* to identify who actually is running this installation and on which device
* the app is installed.
*/
BITAuthenticatorIdentificationTypeAnonymous,
/**
* Ask for the HockeyApp account email
* <br/><br/>
* This will present a user interface requesting the user to provide their
* HockeyApp user email address.
* <br/><br/>
* The provided email address has to match an email address of a registered
* HockeyApp user who is a member or tester of the app
*/
BITAuthenticatorIdentificationTypeHockeyAppEmail,
/**
* Ask for the HockeyApp account by email and password
* <br/><br/>
* This will present a user interface requesting the user to provide their
* HockeyApp user credentials.
* <br/><br/>
* The provided user account has to match a registered HockeyApp user who is
* a member or tester of the app
*/
BITAuthenticatorIdentificationTypeHockeyAppUser,
/**
* Identifies the current device
* <br/><br/>
* This will open the HockeyApp web page on the device in Safari and request the user
* to submit the device's unique identifier to the app. If the web page session is not aware
* of the current devices UDID, it will request the user to install the HockeyApp web clip
* which will provide the UDID to users session in the browser.
* <br/><br/>
* This requires the app to register an URL scheme. See the linked property and methods
* for further documentation on this.
*/
BITAuthenticatorIdentificationTypeDevice,
/**
* Ask for the HockeyApp account email.
* <br/><br/>
* This will present a user interface requesting the user to start a Safari based
* flow to login to HockeyApp (if not already logged in) and to share the hockeyapp
* account's email.
* <br/><br/>
* If restrictApplicationUsage is enabled, the provided user account has to match a
* registered HockeyApp user who is a member or tester of the app.
* For identification purpose any HockeyApp user is allowed.
*/
BITAuthenticatorIdentificationTypeWebAuth,
};
/**
* Restriction enforcement styles
*
* Specifies how often the Authenticator checks if the user is allowed to use
* this app.
*/
typedef NS_ENUM(NSUInteger, BITAuthenticatorAppRestrictionEnforcementFrequency) {
/**
* Checks if the user is allowed to use the app at the first time a version is started
*/
BITAuthenticatorAppRestrictionEnforcementOnFirstLaunch,
/**
* Checks if the user is allowed to use the app every time the app becomes active
*/
BITAuthenticatorAppRestrictionEnforcementOnAppActive,
};
@protocol BITAuthenticatorDelegate;
/**
* Identify and authenticate users of Ad-Hoc or Enterprise builds
*
* `BITAuthenticator` serves 2 purposes:
*
* 1. Identifying who is running your Ad-Hoc or Enterprise builds
* `BITAuthenticator` provides an identifier for the rest of the HockeySDK
* to work with, e.g. in-app update checks and crash reports.
*
* 2. Optional regular checking if an identified user is still allowed
* to run this application. The `BITAuthenticator` can be used to make
* sure only users who are testers of your app are allowed to run it.
*
* This module automatically disables itself when running in an App Store build by default!
*
* @warning It is mandatory to call `authenticateInstallation` somewhen after calling
* `[[BITHockeyManager sharedHockeyManager] startManager]` or fully customize the identification
* and validation workflow yourself.
* If your app shows a modal view on startup, make sure to call `authenticateInstallation`
* either once your modal view is fully presented (e.g. its `viewDidLoad:` method is processed)
* or once your modal view is dismissed.
*/
@interface BITAuthenticator : BITHockeyBaseManager
#pragma mark - Configuration
///-----------------------------------------------------------------------------
/// @name Configuration
///-----------------------------------------------------------------------------
/**
* Defines the identification mechanism to be used
*
* _Default_: `BITAuthenticatorIdentificationTypeAnonymous`
*
* @see BITAuthenticatorIdentificationType
*/
@property (nonatomic, assign) BITAuthenticatorIdentificationType identificationType;
/**
* Enables or disables checking if the user is allowed to run this app
*
* If disabled, the Authenticator never validates, besides initial identification,
* if the user is allowed to run this application.
*
* If enabled, the Authenticator checks depending on `restrictionEnforcementFrequency`
* if the user is allowed to use this application.
*
* Enabling this property and setting `identificationType` to `BITAuthenticatorIdentificationTypeHockeyAppEmail`,
* `BITAuthenticatorIdentificationTypeHockeyAppUser` or `BITAuthenticatorIdentificationTypeWebAuth` also allows
* to remove access for users by removing them from the app's users list on HockeyApp.
*
* _Default_: `NO`
*
* @warning if `identificationType` is set to `BITAuthenticatorIdentificationTypeAnonymous`,
* this property has no effect.
*
* @see BITAuthenticatorIdentificationType
* @see restrictionEnforcementFrequency
*/
@property (nonatomic, assign) BOOL restrictApplicationUsage;
/**
* Defines how often the BITAuthenticator checks if the user is allowed
* to run this application
*
* This requires `restrictApplicationUsage` to be enabled.
*
* _Default_: `BITAuthenticatorAppRestrictionEnforcementOnFirstLaunch`
*
* @see BITAuthenticatorAppRestrictionEnforcementFrequency
* @see restrictApplicationUsage
*/
@property (nonatomic, assign) BITAuthenticatorAppRestrictionEnforcementFrequency restrictionEnforcementFrequency;
/**
* The authentication secret from HockeyApp. To find the right secret,
* click on your app on the HockeyApp dashboard, then on Show next to
* "Secret:".
*
* This is only needed if `identificationType` is set to `BITAuthenticatorIdentificationTypeHockeyAppEmail`
*
* @see identificationType
*/
@property (nonatomic, copy) NSString *authenticationSecret;
#pragma mark - Device based identification
///-----------------------------------------------------------------------------
/// @name Device based identification
///-----------------------------------------------------------------------------
/**
* The baseURL of the webpage the user is redirected to if `identificationType` is
* set to `BITAuthenticatorIdentificationTypeDevice`; defaults to https://rink.hockeyapp.net.
*
* @see identificationType
*/
@property (nonatomic, strong) NSURL *webpageURL;
/**
* URL to query the device's id via external webpage
* Built with the baseURL set in `webpageURL`.
*/
- (NSURL*) deviceAuthenticationURL;
/**
* The url-scheme used to identify via `BITAuthenticatorIdentificationTypeDevice`
*
* Please make sure that the URL scheme is unique and not shared with other apps.
*
* If set to nil, the default scheme is used which is `ha<APP_ID>`.
*
* @see identificationType
* @see handleOpenURL:sourceApplication:annotation:
*/
@property (nonatomic, copy) NSString *urlScheme;
/**
Should be used by the app-delegate to forward handle application:openURL:sourceApplication:annotation: calls.
This is required if `identificationType` is set to `BITAuthenticatorIdentificationTypeDevice`.
Your app needs to implement the default `ha<APP_ID>` URL scheme or register its own scheme
via `urlScheme`.
BITAuthenticator checks if the given URL is actually meant to be parsed by it and will
return NO if it doesn't think so. It does this by checking the 'host'-part of the URL to be 'authorize', as well
as checking the protocol part.
Please make sure that if you're using a custom URL scheme, it does _not_ conflict with BITAuthenticator's.
If BITAuthenticator thinks the URL was meant to be an authorization URL, but could not find a valid token, it will
reset the stored identification token and state.
Sample usage (in AppDelegate):
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([[BITHockeyManager sharedHockeyManager].authenticator handleOpenURL:url
sourceApplication:sourceApplication
annotation:annotation]) {
return YES;
} else {
//do your own URL handling, return appropriate value
}
return NO;
}
@param url Param `url` that was passed to the app
@param sourceApplication Param `sourceApplication` that was passed to the app
@param annotation Param `annotation` that was passed to the app
@return YES if the URL request was handled, NO if the URL could not be handled/identified.
@see identificationType
@see urlScheme
*/
- (BOOL) handleOpenURL:(NSURL *) url
sourceApplication:(NSString *) sourceApplication
annotation:(id) annotation;
#pragma mark - Authentication
///-----------------------------------------------------------------------------
/// @name Authentication
///-----------------------------------------------------------------------------
/**
* Invoked automatic identification and validation
*
* If the `BITAuthenticator` is in automatic mode this will initiate identifying
* the current user according to the type specified in `identificationType` and
* validate if the identified user is allowed to run this application.
*
* If the user is not yet identified it will present a modal view asking the user to
* provide the required information.
*
* If your app provides it's own startup modal screen, e.g. a guide or a login, then
* you might either call this method once that UI is fully presented or once
* the user e.g. did actually login already.
*
* @warning You need to call this method in your code even if automatic mode is enabled!
*
* @see identificationType
*/
- (void) authenticateInstallation;
/**
* Identifies the user according to the type specified in `identificationType`.
*
* If the `BITAuthenticator` is in manual mode, it's your responsibility to call
* this method. Depending on the `identificationType`, this method
* might present a viewController to let the user enter his/her credentials.
*
* If the Authenticator is in auto-mode, this is called by the authenticator itself
* once needed.
*
* @see identificationType
* @see authenticateInstallation
* @see validateWithCompletion:
*
* @param completion Block being executed once identification completed. Be sure to properly dispatch code to the main queue if necessary.
*/
- (void) identifyWithCompletion:(void(^)(BOOL identified, NSError *error)) completion;
/**
* Returns YES if this app is identified according to the setting in `identificationType`.
*
* Since the identification process is done asynchronously (contacting the server),
* you need to observe the value change via KVO.
*
* @see identificationType
*/
@property (nonatomic, assign, readonly, getter = isIdentified) BOOL identified;
/**
* Validates if the identified user is allowed to run this application. This checks
* with the HockeyApp backend and calls the completion-block once completed.
*
* If the `BITAuthenticator` is in manual mode, it's your responsibility to call
* this method. If the application is not yet identified, validation is not possible
* and the completion-block is called with an error set.
*
* If the `BITAuthenticator` is in auto-mode, this is called by the authenticator itself
* once needed.
*
* @see identificationType
* @see authenticateInstallation
* @see identifyWithCompletion:
*
* @param completion Block being executed once validation completed. Be sure to properly dispatch code to the main queue if necessary.
*/
- (void) validateWithCompletion:(void(^)(BOOL validated, NSError *error)) completion;
/**
* Indicates if this installation is validated.
*/
@property (nonatomic, assign, readonly, getter = isValidated) BOOL validated;
/**
* Removes all previously stored authentication tokens, UDIDs, etc.
*/
- (void) cleanupInternalStorage;
/**
* Returns different values depending on `identificationType`. This can be used
* by the application to identify the user.
*
* @see identificationType
*/
- (NSString*) publicInstallationIdentifier;
@end
#pragma mark - Protocol
/**
* `BITAuthenticator` protocol
*/
@protocol BITAuthenticatorDelegate <NSObject>
@optional
/**
* If the authentication (or validation) needs to identify the user,
* this delegate method is called with the viewController that we'll present.
*
* @param authenticator `BITAuthenticator` object
* @param viewController `UIViewController` used to identify the user
*
*/
- (void) authenticator:(BITAuthenticator *)authenticator willShowAuthenticationController:(UIViewController*) viewController;
@end