cordova-digital-onboarding 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,382 @@
1
+ # Verifying user
2
+
3
+ If your PowerAuthSDK instance was activated with the `WDOActivationService`, it will be in the state that needs additional verification. Without such verification, it won't be able to properly sign requests.
4
+
5
+ Additional verification means that the user will need to scan his face and documents like ID and/or passport.
6
+
7
+ ## When is the verification needed?
8
+
9
+ Verification is needed if the `activationFlags` in the `PowerAuthActivationStatus` contains `VERIFICATION_PENDING` or `VERIFICATION_IN_PROGRESS` value.
10
+
11
+ To simplify this check, you can use the `WDOVerificationService.isVerificationRequired` method that returns a boolean indicating whether verification is required.
12
+
13
+ Example:
14
+
15
+ ```typescript
16
+ const powerAuth: PowerAuth // configured and activated PowerAuth instance
17
+
18
+ try {
19
+ const status = await powerAuth.fetchActivationStatus()
20
+ if (WDOVerificationService.isVerificationRequired(status)) {
21
+ // navigate to the verification flow
22
+ // and call `WDOVerificationService.status`
23
+ } else {
24
+ // handle PA status
25
+ }
26
+ } catch (error) {
27
+ // handle error
28
+ }
29
+ ```
30
+
31
+ ## Example app flow
32
+
33
+ <p align="center"><img src="images/verification-mockup.png" alt="Example verification flow" width="100%" /></p>
34
+
35
+ <!-- begin box info -->
36
+ This mockup shows a __happy user flow__ of an example setup. Your usage may vary.
37
+ The final flow (which screens come after another) is controlled by the backend.
38
+ <!-- end -->
39
+
40
+ ## Server driven flow
41
+
42
+ - The screen that should be displayed is driven by the state on the server "session".
43
+ - At the beginning of the verification process, you will call the status which will tell you what to display to the user and which function to call next.
44
+ - Each API call returns a result and a next screen to display.
45
+ - This repeats until the process is finished or an "endstate state" is presented which terminates the process.
46
+
47
+ ## Possible state values
48
+
49
+ State is defined by the `WDOVerificationStateType` enum with the following possibilities:
50
+
51
+ ```typescript
52
+ /** Types of the verification state */
53
+ declare enum WDOVerificationStateType {
54
+ /**
55
+ * Show the verification introduction screen where the user can start the activation.
56
+ *
57
+ * The next step should be calling the `consentGet()`.
58
+ */
59
+ intro = "intro",
60
+ /**
61
+ * Show approve/cancel user consent.
62
+ *
63
+ * The content of the text depends on the server configuration and might be plain text or HTML.
64
+ *
65
+ * The next step should be calling the `consentApprove`.
66
+ */
67
+ consent = "consent",
68
+ /**
69
+ * Show document selection to the user. Which documents are available and how many
70
+ * can the user select is up to your backend configuration.
71
+ *
72
+ * The next step should be calling the `documentsSetSelectedTypes`.
73
+ */
74
+ documentsToScanSelect = "documentsToScanSelect",
75
+ /**
76
+ * User should scan documents - display UI for the user to scan all necessary documents.
77
+ *
78
+ * The next step should be calling the `documentsSubmit`.
79
+ */
80
+ scanDocument = "scanDocument",
81
+ /**
82
+ * The system is processing data - show loading with text hint from provided `WDOStatusCheckReason`.
83
+ *
84
+ * The next step should be calling the `status`.
85
+ */
86
+ processing = "processing",
87
+ /**
88
+ * The user should be presented with a presence check.
89
+ * Presence check is handled by third-party SDK based on the project setup.
90
+ *
91
+ * The next step should be calling the `presenceCheckInit` to start the check and `presenceCheckSubmit` to
92
+ * mark it finished. Note that these methods won't change the status and it's up to the app to handle the process of the presence check.
93
+ */
94
+ presenceCheck = "presenceCheck",
95
+ /**
96
+ * Show enter OTP screen with resend button.
97
+ *
98
+ * The next step should be calling the `verifyOTP` with user-entered OTP.
99
+ * The OTP is usually SMS or email.
100
+ */
101
+ otp = "otp",
102
+ /**
103
+ * Verification failed and can be restarted
104
+ *
105
+ * The next step should be calling the `restartVerification` or `cancelWholeProcess` based on
106
+ * the user's decision if he wants to try it again or cancel the process.
107
+ */
108
+ failed = "failed",
109
+ /**
110
+ * Verification is canceled and the user needs to start again with a new PowerAuth activation.
111
+ *
112
+ * The next step should be calling the `PowerAuth.removeActivationLocal()` and starting activation from scratch.
113
+ */
114
+ endState = "endState",
115
+ /**
116
+ * Verification was successfully ended. Continue into your app flow.
117
+ */
118
+ success = "success"
119
+ }
120
+ ```
121
+
122
+ ## Creating an instance
123
+
124
+ To create an instance you will need a `PowerAuth` instance that is __already activated__.
125
+
126
+ <!-- begin box info -->
127
+ [Documentation for `PowerAuth`](https://github.com/wultra/react-native-powerauth-mobile-sdk).
128
+ <!-- end -->
129
+
130
+
131
+ Example:
132
+ ```typescript
133
+ const powerAuth = new PowerAuth("my-pa-instance")
134
+ powerAuth.configure({
135
+ configuration: "ARCB+...jg==", // base64 PowerAuth configuration
136
+ baseEndpointUrl: "https://my-server-deployment.com/enrollment-server/"
137
+ })
138
+ const verification = new WDOVerificationService(
139
+ powerAuth,
140
+ "https://my-server-deployment.com/enrollment-server-onboarding/"
141
+ )
142
+ ```
143
+
144
+ ## Getting the verification status
145
+
146
+ When entering the verification flow for the first time (for example fresh app start), you need to retrieve the state of the verification.
147
+
148
+ The same needs to be done after some operation fails and it's not sure what is the next step in the verification process.
149
+
150
+ Most verification functions return the result and also the state for your convenience of "what next".
151
+
152
+ Getting the state directly:
153
+
154
+ ```typescript
155
+ const verification: WDOVerificationService // configured instance
156
+ try {
157
+ const vfStatus = await verification.status()
158
+ // handle `WDOVerificationState` state and navigate to the expected screen
159
+ } catch (error) {
160
+ if (error.verificationState) {
161
+ // show expected screen based on the state
162
+ } else {
163
+ // navigate to error screen
164
+ }
165
+ }
166
+ ```
167
+
168
+ ## Getting the user consent text
169
+
170
+ When the state is `intro`, the first step in the flow is to get the context text for the user to approve.
171
+
172
+ ```typescript
173
+ const verification: WDOVerificationService // configured instance
174
+ try {
175
+ const consentTextResponse = await verification.consentGet()
176
+ // state will be in the `consent` case here - display the consent screen
177
+ } catch (error) {
178
+ if (error.verificationState) {
179
+ // show expected screen based on the state
180
+ } else {
181
+ // navigate to error screen
182
+ }
183
+ }
184
+ ```
185
+
186
+ ## Approving the user consent
187
+
188
+ When the state is `consent`, you should display the consent text to the user to approve or reject.
189
+
190
+ If the user __rejects the consent__, just return him to the intro screen, there's no API call for reject.
191
+
192
+ If the user chooses to accept the consent, call `consentApprove` function. If successful, `documentsToScanSelect` state will be returned.
193
+
194
+ ```typescript
195
+ const verification: WDOVerificationService // configured instance
196
+ try {
197
+ const approvalResult = await verification.consentApprove()
198
+ // state will be in the `documentsToScanSelect` case here - display the document selector
199
+ } catch (error) {
200
+ if (error.verificationState) {
201
+ // show expected screen based on the state
202
+ } else {
203
+ // navigate to error screen
204
+ }
205
+ }
206
+ ```
207
+
208
+ ## Set document types to scan
209
+
210
+ After the user approves the consent, present a document selector for documents which will be scanned. The number and types of documents (or other rules like 1 type required) are completely dependent on your backend system integration. You can retrieve the list of available document types from the [configuration service](Process-Configuration.md).
211
+
212
+ For example, your system might require a national ID and one additional document like a driver's license, passport, or any other government-issued personal document.
213
+
214
+ ```typescript
215
+ const verification: WDOVerificationService // configured instance
216
+ try {
217
+ const docTypesResult = await verification.documentsSetSelectedTypes([
218
+ WDODocumentType.idCard,
219
+ WDODocumentType.driversLicense
220
+ ])
221
+ // state will be in the `scanDocument` case here - display the document scanner
222
+ } catch (error) {
223
+ if (error.verificationState) {
224
+ // show expected screen based on the state
225
+ } else {
226
+ // navigate to error screen
227
+ }
228
+ }
229
+ ```
230
+
231
+ ## Configuring the "Document Scan SDK"
232
+
233
+ <!-- begin box info -->
234
+ This step does not move the state of the process but is a "stand-alone" API call.
235
+ <!-- end -->
236
+
237
+ Since the document scanning itself is not provided by this library but by a 3rd party library, some of them need a server-side initialization.
238
+
239
+ If your chosen scanning SDK requires such a step, use this function to retrieve necessary data from the server.
240
+
241
+ ## Scanning a document
242
+
243
+ When the state of the process is `scanDocument` with the `WDOVerificationScanProcess` parameter, you need to present a document scan UI to the user. This UI needs
244
+ to guide through the scanning process - scanning one document after another and both sides (if the document requires so).
245
+
246
+ The whole UI and document scanning process is up to you and the 3rd party library you choose to use.
247
+
248
+ <!-- begin box warning -->
249
+ This step is the most complicated in the process as you need to integrate this SDK, another document-scanning SDK, and integrate your server-side expected logic. To
250
+ make sure everything goes as smoothly as possible, ask your project management to provide you with a detailed description/document of the required scenarios and expected documents
251
+ for your implementation.
252
+ <!-- end -->
253
+
254
+ ## Uploading a document
255
+
256
+ When a document is scanned (both sides when required), it needs to be uploaded to the server.
257
+
258
+ <!-- begin box warning -->
259
+ __Images of the document should not be bigger than 1MB. Files that are too big will take longer time to upload and process on the server.__
260
+ <!-- end -->
261
+
262
+ To upload a document, use `documentsSubmit` function. Each side of a document is a single `WDODocumentFile` instance.
263
+
264
+ Example:
265
+
266
+ ```typescript
267
+ const verification: WDOVerificationService // configured instance
268
+
269
+ const passportToUpload = WDODocumentFile(
270
+ "BASE64_ENCODED_IMAGE_DATA", // raw image data from the document scanning library/photo camera
271
+ WDODocumentType.passport,
272
+ WDODocumentSide.front, // passport has only front side
273
+ undefined, // use only when re-uploading the file (for example when first upload was rejected because of a blur)
274
+ undefined // optional, use when provided by the document scanning library
275
+ )
276
+ try {
277
+ const result = await verification.documentsSubmit([passportToUpload])
278
+ // state will be in the `processing` case here - display the processing screen
279
+ } catch (error) {
280
+ if (error.verificationState) {
281
+ // show expected screen based on the state
282
+ } else {
283
+ // navigate to error screen
284
+ }
285
+ }
286
+ ```
287
+
288
+ ### `WDODocumentFile`
289
+
290
+ ```typescript
291
+ /** Image of a document that can be sent to the backend for Identity Verification. */
292
+ declare class WDODocumentFile {
293
+ /** Raw data to upload. Make sure that the data aren't too big, hundreds of kbs should be enough. */
294
+ data: Base64EncodedJPEG;
295
+ /**
296
+ * Image signature.
297
+ *
298
+ * Optional, use only when the scan SDK supports this.
299
+ */
300
+ dataSignature: string | undefined;
301
+ /** Type of the document. */
302
+ type: WDODocumentType;
303
+ /** Side of the document (`front` if the document is one-sided or only one side is expected). */
304
+ side: WDODocumentSide;
305
+ /**
306
+ * For image reuploading when the previous file of the same document was rejected.
307
+ *
308
+ * Without specifying this value, the document side won't be overwritten.
309
+ */
310
+ originalDocumentId: string | undefined;
311
+ /**
312
+ * Create the document file from an image that can be sent to the backend for Identity Verification.
313
+ *
314
+ * @param scannedDocument Document to upload.
315
+ * @param side The side of the document that the image captures.
316
+ * @param data Raw image data. Make sure that the data aren't too big, hundreds of kbs should be enough.
317
+ * @param dataSignature Signature of the image data. Optional, use only when the scan SDK supports this. `undefined` by default.
318
+ * @returns Document file to upload.
319
+ */
320
+ static fromScannedDocument(scannedDocument: WDOScannedDocument, side: WDODocumentSide, data: Base64EncodedJPEG, dataSignature?: string): WDODocumentFile;
321
+ /**
322
+ * Image of a document that can be sent to the backend for Identity Verification.
323
+ *
324
+ * @param data Raw image data. Make sure that the data aren't too big, hundreds of kbs should be enough.
325
+ * @param type Type of the document.
326
+ * @param side The side of the document that the image captures.
327
+ * @param originalDocumentId Original document ID In case of a reupload. If you've previously uploaded this type and side and won't specify the previous ID, the image won't be overwritten.
328
+ * @param dataSignature Signature of the image data. Optional, use only when the scan SDK supports this. `undefined` by default.
329
+ */
330
+ constructor(data: Base64EncodedJPEG, type: WDODocumentType, side: WDODocumentSide, originalDocumentId?: string, dataSignature?: string);
331
+ }
332
+ ```
333
+
334
+ <!-- begin box info -->
335
+ To create an instance of the `WDODocumentFile`, you can use `WDODocumentFile.fromScannedDocument`. The `WDOScannedDocument` is returned in the process status as a "next document to scan".
336
+ <!-- end -->
337
+
338
+ ## Presence check
339
+
340
+ To verify that the user is present in front of the phone, a presence check is required. This is suggested by the `presenceCheck` state.
341
+
342
+ When this state is obtained, the following steps need to be done:
343
+
344
+ 1. Call `presenceCheckInit` to initialize the presence check on the server. This call returns a dictionary of necessary data for the presence-check library to initialize.
345
+ 2. Make the presence check by the third-party library
346
+ 3. After the presence check is finished, call `presenceCheckSubmit` to tell the server you finished the process on the device.
347
+
348
+ ## Verify OTP (optional step)
349
+
350
+ After the presence check is finished, the user will receive an SMS/email OTP and the `otp` state will be reported. When this state is received, prompt the user for the OTP and verify it via `verifyOTP` method.
351
+
352
+ The `otp` state also contains the number of possible OTP attempts. When attempts are depleted, the error state is returned.
353
+
354
+ Example:
355
+
356
+ ```typescript
357
+ const verification: WDOVerificationService // configured instance
358
+ try {
359
+ const otpStatus = await verificationService.verifyOTP("123456")
360
+ // React to a new state returned in the result
361
+ } catch (error) {
362
+ // handle error
363
+ }
364
+ ```
365
+
366
+ ## Success state
367
+
368
+ When a whole verification is finished, you will receive the `success` state. Show a success screen and navigate the user to a common activated flow.
369
+
370
+ At the same time, the verification flags from the PowerAuth status are removed.
371
+
372
+ ## Failed state
373
+
374
+ When the process fails, a `failed` state is returned. This means that the current verification process has failed and the user can restart it (by calling the `restartVerification` function) and start again (by showing the intro).
375
+
376
+ ## Endstate state
377
+
378
+ When the activation is no longer able to be verified (for example did several failed attempts or took too long to finish), the `endstate` state is returned. In this state there's nothing the user can do to continue. `cancelWholeProcess` shall be called and `removeActivationLocal` should be called on the PowerAuth object. After that, user should be put inti the "fresh install state".
379
+
380
+ ## Read next
381
+
382
+ - [Language Configuration](Language-Configuration.md)
@@ -0,0 +1,12 @@
1
+ **Tutorials**
2
+
3
+ - [SDK Integration](SDK-Integration.md)
4
+ - [Process Configuration](Process-Configuration.md)
5
+ - [Device Activation (With Weak Credentials)](Device-Activation.md)
6
+ - [Verifying User With Document Scan And Genuine Presence Check](Verifying-User.md)
7
+ - [Language Configuration](Language-Configuration.md)
8
+ - [Logging](Logging.md)
9
+
10
+ **Other**
11
+
12
+ - [Changelog](./Changelog.md)
Binary file