-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcognito.php
More file actions
404 lines (374 loc) · 16.2 KB
/
cognito.php
File metadata and controls
404 lines (374 loc) · 16.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php
/*
* This file is part of AWS Cognito Auth solution.
*
* (c) EllaiSys <ellaisys@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Ellaisys\Cognito\Enums\CognitoChallengeTypes;
$allowPhoneNumber = env('AWS_COGNITO_MFA_SETUP', 'MFA_NONE') === 'MFA_ENABLED' ||
in_array(env('AWS_COGNITO_ADD_USER_DELIVERY_MEDIUMS', 'BOTH'), ['SMS', 'BOTH']) ||
env('AWS_COGNITO_ALLOW_PHONE_NUMBER', false);
return [
/*
|--------------------------------------------------------------------------
| AWS configurations
|--------------------------------------------------------------------------
|
| If you have created the aws iam users, you should set the details from
| the aws console within your environment file. These values will
| get used while connecting with the aws using the official sdk.
|
*/
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'token' => null
],
/*
|--------------------------------------------------------------------------
| AWS Cognito configurations
|--------------------------------------------------------------------------
|
| If you have created the aws cognito , you should set the details from
| the aws console within your environment file. These values will
| get used while issuing fresh personal access tokens to your users.
|
*/
'app_client_id' => env('AWS_COGNITO_CLIENT_ID'),
'app_client_secret' => env('AWS_COGNITO_CLIENT_SECRET'),
'user_pool_id' => env('AWS_COGNITO_USER_POOL_ID'),
'region' => env('AWS_COGNITO_REGION', 'us-east-1'),
'version' => env('AWS_COGNITO_VERSION', 'latest'),
/*
|--------------------------------------------------------------------------
| AWS Cognito for Allowing the App Client Secret
|--------------------------------------------------------------------------
|
| If you have created the aws cognito, and don't plan to set the client
| secret, then use this configuration to help. By default we expect the
| client secret is configured and available.
|
*/
'app_client_secret_allow' => env('AWS_COGNITO_CLIENT_SECRET_ALLOW', true),
/*
|--------------------------------------------------------------------------
| AWS Cognito Path
|--------------------------------------------------------------------------
|
| This is the base URI path where the package views, such as the MFA
| verification screen, activation screen, etc will be available from.
| You're free to tweak this path according to your preferences and
| application design.
|
*/
'path' => env('AWS_COGNITO_PATH', ''),
/*
|--------------------------------------------------------------------------
| Web Path Prefix
|--------------------------------------------------------------------------
|
| This is the Web Prefix for the endpoint. You can change is such that it
| does not cause any conflict with your existing web endpoints or as per
| your application design.
|
| The default value is set to 'cognito'.
|
*/
'web_prefix' => env('AWS_COGNITO_WEB_PREFIX', 'cognito'),
/*
|--------------------------------------------------------------------------
| API Path Prefix
|--------------------------------------------------------------------------
|
| This is the API Prefix for the endpoint. You can change is such that it
| does not cause any conflict with your existing API endpoints or as per
| your application design.
|
| The default value is set to 'cognito'.
|
*/
'api_prefix' => env('AWS_COGNITO_API_PREFIX', 'cognito'),
/*
|--------------------------------------------------------------------------
| AWS Cognito Home Route Name
|--------------------------------------------------------------------------
|
| This is the home route name where the page redirects post successful
| authentication. This will work with and without the MFA enabled using
| the AWS Cognito based authentication. This is applicable for web routes
| only.
|
| The default value is set to 'home'.
|
*/
'redirect_to_route_name' => env('AWS_COGNITO_HOME_ROUTE_NAME', 'cognito.home'),
/*
|--------------------------------------------------------------------------
| Cognito Fields & DB Mapping
|--------------------------------------------------------------------------
|
| This option controls the default cognito fields that shall be needed to be
| updated. The array value is a mapping with DB model or Request data.
|
| DO NOT change the parameters on the left side of the array. They map to
| the AWS Cognito User Pool fields.
|
| The right side of the array is the DB model field, and you can set the
| value to null if you do not want to update the field.
|
*/
'cognito_user_fields' => [
'name' => 'name',
'given_name' => null,
'middle_name' => null,
'family_name' => null,
'nickname' => null,
'preferred_username' => null,
'email' => 'email', //Do Not set this parameter to null
'phone_number' => $allowPhoneNumber ? 'phone' : null,
'gender' => null,
'birthdate' => null,
'locale' => null
],
/*
|--------------------------------------------------------------------------
| Cognito Subject UUID
|--------------------------------------------------------------------------
|
| This option controls the default cognito subject UUID that shall be needed
| to be updated based on your local DB schema. This value is the attribute
| in the local DB Model that maps with Cognito user subject UUID.
|
*/
'user_subject_uuid' => env('AWS_COGNITO_USER_SUBJECT_UUID', 'sub'),
/*
|--------------------------------------------------------------------------
| Cognito New User
|--------------------------------------------------------------------------
|
| This option controls the default cognito when a new user is add to the
| User Pool.
|
| The options available are "NONE", "BOTH", "EMAIL", "SMS"
|
*/
'add_user_delivery_mediums' => env('AWS_COGNITO_ADD_USER_DELIVERY_MEDIUMS', 'BOTH'),
/*
|--------------------------------------------------------------------------
| Cognito Default User Group
|--------------------------------------------------------------------------
|
| This option controls the default cognito user group assigned to a user
| when added to a User Pool. Leave null if not assigning a group on
| registration.
|
|
*/
'default_user_group' => env('AWS_COGNITO_DEFAULT_USER_GROUP', null),
/*
|--------------------------------------------------------------------------
| Cognito MFA Setup and configurations
|--------------------------------------------------------------------------
|
| This option controls the cognito MFA configuration to be used for the
| users in the User Pool. The options available are "MFA_NONE" and
| "MFA_ENABLED". The default value is set to "MFA_NONE" which means that
| the MFA is not enabled for the users.
|
| MFA_NONE, MFA_ENABLED
|
*/
'mfa_setup' => env('AWS_COGNITO_MFA_SETUP', 'MFA_NONE'),
'force_mfa_code_route_name' => env('AWS_COGNITO_MFA_CODE_ROUTE_NAME', 'cognito.form.login'),
/*
|--------------------------------------------------------------------------
| Cognito MFA Types supported
|--------------------------------------------------------------------------
|
| This option controls the default cognito MFA types allowed if the MFA is
| enabled for the user. The options available are "SMS_MFA" and
| "SOFTWARE_TOKEN_MFA". The default value is set to "SOFTWARE_TOKEN_MFA".
| In case you want to allow both the MFA types, you can set the value to
| "SMS_MFA,SOFTWARE_TOKEN_MFA" separated by comma.
|
| The first MFA type in the list will be set as preferred MFA type.
|
*/
'mfa_type' => env('AWS_COGNITO_MFA_TYPE', 'SOFTWARE_TOKEN_MFA'),
/*
|--------------------------------------------------------------------------
| SSO Settings
|--------------------------------------------------------------------------
|
| This option controls the SSO settings into the application.
|
*/
'add_missing_local_user' => env('AWS_COGNITO_ADD_LOCAL_USER', false),
'delete_user' => env('AWS_COGNITO_DELETE_USER', false),
// Package configurations
'sso_user_model' => env('AWS_COGNITO_USER_MODEL', 'App\Models\User'),
/*
|--------------------------------------------------------------------------
| Token Store
|--------------------------------------------------------------------------
|
| This option controls the default store connection provider that gets used
| while persisting the token. You can use the providers in the cache config.
|
*/
'storage_provider' => env('AWS_COGNITO_TOKEN_STORAGE', 'file'),
/*
|--------------------------------------------------------------------------
| Cognito Challenge Status Names for Forced Password Change.
|--------------------------------------------------------------------------
|
| This option controls the package action based on the Challenge Status
| received from the AWS Cognito Authentication. If the challenge status
| is 'NEW_PASSWORD_REQUIRED' and/or 'RESET_REQUIRED', this
| configuration will force the user to change their password.
|
*/
'forced_challenge_names' => [
CognitoChallengeTypes::NEW_PASSWORD_REQUIRED,
CognitoChallengeTypes::RESET_REQUIRED
],
/*
|--------------------------------------------------------------------------
| Force Password Change by the User based on Cognito Status in Web Request
| (Session Guard)
|--------------------------------------------------------------------------
|
| This setting controls the action, in case the AWS Cognito authentication
| response includes the Challenge Names defined by 'forced_challenge_names'
| configuration in this file. The below flag, if set to 'true', will force
| the web application user to be directed to certain route view/page.
|
| In case the route name needs to be changed, you can set the below parameter
| and map it in web.php route page.
|
*/
'force_password_change_web' => env('AWS_COGNITO_FORCE_PASSWORD_CHANGE_WEB', true),
'force_redirect_route_name' => env('AWS_COGNITO_FORCE_PASSWORD_ROUTE_NAME', 'cognito.form.change.password'),
/*
|--------------------------------------------------------------------------
| Force Password Change by User based on Cognito Status in API Request (Token Guard)
|--------------------------------------------------------------------------
|
| This setting controls the action, in case the AWS Cognito authentication
| response includes the Challenge Names defined by 'forced_challenge_names'
| configuration in this file. The below flag, if set to 'true', will force
| the user requesting API authentication by sharing the data required for
| changing the password.
|
*/
'force_password_change_api' => env('AWS_COGNITO_FORCE_PASSWORD_CHANGE_API', true),
/*
|--------------------------------------------------------------------------
| Force Auto Password Update based on Cognito Status in API Request (Token Guard)
|--------------------------------------------------------------------------
|
| This option enables the password to be auto updated into the AWS Cognito
| User Pool. This feature will work only if the 'force_password_change_api'
| is set to false.
|
*/
'force_password_auto_update_api' => env('AWS_COGNITO_FORCE_PASSWORD_AUTO_UPDATE_API', false),
/*
|--------------------------------------------------------------------------
| Allow forgot password to resend the request based on Cognito User Status
|--------------------------------------------------------------------------
|
| This option enables the user to request for password from the AWS Cognito
| User Pool, where the user is not with confirmed status.
|
*/
'allow_forgot_password_resend' => env('AWS_COGNITO_ALLOW_FORGOT_PASSWORD_RESEND', true),
/*
|--------------------------------------------------------------------------
| Allow new user email address to be verified during invitation
|--------------------------------------------------------------------------
|
| This option enables the user email address to be tagged as verified during
| the to invitation for the new user. The default value is set to true.
|
*/
'force_new_user_email_verified' => env('AWS_COGNITO_FORCE_NEW_USER_EMAIL_VERIFIED', false),
/*
|--------------------------------------------------------------------------
| Set the parameters for the new user message action
|--------------------------------------------------------------------------
|
| This option enables the new user message action. You can set the value to
| SUPPRESS in order to stop the invitation mails from being sent. The default
| value is set to null.
|
| Possible values: "RESEND", "SUPPRESS"
|
*/
'new_user_message_action' => env('AWS_COGNITO_NEW_USER_MESSAGE_ACTION', null),
/*
|--------------------------------------------------------------------------
| Allow new user to set the password and have verified
|--------------------------------------------------------------------------
|
| This option enables the user to set the custom password and have that
| verified during the to invitation for the new user. The default value
| is set to true.
| Setting the value to false will auto generate a random password and
| send it to the user via email or SMS
|
*/
'force_new_user_password' => env('AWS_COGNITO_FORCE_NEW_USER_PASSWORD', true),
/*
|--------------------------------------------------------------------------
| Allow new user configure the MFA QR Library
|--------------------------------------------------------------------------
|
| This option enables the user to set the MFA QR code library to be used
| during the to invitation for the new user. The default value is set
| currently to https://quickchart.io/qr. The TOPT URL will be appended to
| the end of the this library URL
|
| For configuration & customizations of QuickChart
| Refer https://quickchart.io/documentation/qr-codes/ for more details.
|
*/
'mfa_qr_library' => env('AWS_COGNITO_MFA_QR_LIBRARY', 'https://quickchart.io/qr?size=200&text='),
/*
|--------------------------------------------------------------------------
| Registration Type
|--------------------------------------------------------------------------
| This option controls the registration type for new users. The options
| available are "register" and "invite". The default value is set to
| "register".
|
*/
'registration_type' => env('AWS_COGNITO_REGISTRATION_TYPE', 'register'),
/*
|--------------------------------------------------------------------------
| Views
|--------------------------------------------------------------------------
| This option controls the views for the package. You can set the layout
| for the views here.
*/
'views' => [
'layout' => env('AWS_COGNITO_VIEWS_LAYOUT', 'cognito::layouts.app'),
],
/*
|--------------------------------------------------------------------------
| Routes
|--------------------------------------------------------------------------
| This option controls the routes for the package. You can set the routes
| for the package here.
*/
'routes' => [
'web' => [
'default_root_page' => env('AWS_COGNITO_DEFAULT_ROOT_PAGE', ''),
'login_page' => env('AWS_COGNITO_LOGIN_PAGE', 'cognito.form.login'),
'home_page' => env('AWS_COGNITO_HOME_ROUTE_NAME', 'cognito.home'),
]
]
];