1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Passport\Entities; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2019 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Limoncello\Passport\Contracts\Entities\DatabaseSchemaInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package Limoncello\Passport |
25
|
|
|
* |
26
|
|
|
* @SuppressWarnings(PHPMD) |
27
|
|
|
*/ |
28
|
|
|
class DatabaseSchema implements DatabaseSchemaInterface |
29
|
|
|
{ |
30
|
|
|
/** Table name */ |
31
|
|
|
const TABLE_CLIENTS = 'oauth_clients'; |
32
|
|
|
|
33
|
|
|
/** View name */ |
34
|
|
|
const VIEW_CLIENTS = 'vw_oauth_clients'; |
35
|
|
|
|
36
|
|
|
/** Table name */ |
37
|
|
|
const TABLE_CLIENTS_SCOPES = 'oauth_clients_scopes'; |
38
|
|
|
|
39
|
|
|
/** Table name */ |
40
|
|
|
const TABLE_REDIRECT_URIS = 'oauth_redirect_uris'; |
41
|
|
|
|
42
|
|
|
/** Table name */ |
43
|
|
|
const TABLE_SCOPES = 'oauth_scopes'; |
44
|
|
|
|
45
|
|
|
/** Table name */ |
46
|
|
|
const TABLE_TOKENS = 'oauth_tokens'; |
47
|
|
|
|
48
|
|
|
/** View name */ |
49
|
|
|
const VIEW_TOKENS = 'vw_oauth_tokens'; |
50
|
|
|
|
51
|
|
|
/** Table name */ |
52
|
|
|
const TABLE_TOKENS_SCOPES = 'oauth_tokens_scopes'; |
53
|
|
|
|
54
|
|
|
/** View name */ |
55
|
|
|
const VIEW_USERS = 'vw_oauth_users'; |
56
|
|
|
|
57
|
|
|
/** Field name */ |
58
|
|
|
const CLIENTS_SCOPES_FIELD_ID = 'clients_scopes_id'; |
59
|
|
|
|
60
|
|
|
/** Field name */ |
61
|
|
|
const TOKENS_SCOPES_FIELD_ID = 'tokens_scopes_id'; |
62
|
|
|
|
63
|
|
|
/** View name */ |
64
|
|
|
const VIEW_PASSPORT = 'vw_oauth_passport'; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string|null |
68
|
|
|
*/ |
69
|
|
|
private $usersTableName; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var string|null |
73
|
|
|
*/ |
74
|
|
|
private $usersIdColumn; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param null|string $usersTableName |
78
|
|
|
* @param null|string $usersIdColumn |
79
|
|
|
*/ |
80
|
80 |
|
public function __construct(string $usersTableName = null, string $usersIdColumn = null) |
81
|
|
|
{ |
82
|
80 |
|
$this->usersTableName = $usersTableName; |
83
|
80 |
|
$this->usersIdColumn = $usersIdColumn; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdoc |
88
|
|
|
*/ |
89
|
66 |
|
public function getClientsTable(): string |
90
|
|
|
{ |
91
|
66 |
|
return static::TABLE_CLIENTS; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @inheritdoc |
96
|
|
|
*/ |
97
|
5 |
|
public function getClientsView(): string |
98
|
|
|
{ |
99
|
5 |
|
return static::VIEW_CLIENTS; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @inheritdoc |
104
|
|
|
*/ |
105
|
3 |
|
public function getClientsViewScopesColumn(): string |
106
|
|
|
{ |
107
|
3 |
|
return Client::FIELD_SCOPES; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @inheritdoc |
112
|
|
|
*/ |
113
|
3 |
|
public function getClientsViewRedirectUrisColumn(): string |
114
|
|
|
{ |
115
|
3 |
|
return Client::FIELD_REDIRECT_URIS; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @inheritdoc |
120
|
|
|
*/ |
121
|
38 |
|
public function getClientsIdentityColumn(): string |
122
|
|
|
{ |
123
|
38 |
|
return Client::FIELD_ID; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
34 |
|
public function getClientsNameColumn(): string |
130
|
|
|
{ |
131
|
34 |
|
return Client::FIELD_NAME; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @inheritdoc |
136
|
|
|
*/ |
137
|
34 |
|
public function getClientsDescriptionColumn(): string |
138
|
|
|
{ |
139
|
34 |
|
return Client::FIELD_DESCRIPTION; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @inheritdoc |
144
|
|
|
*/ |
145
|
34 |
|
public function getClientsCredentialsColumn(): string |
146
|
|
|
{ |
147
|
34 |
|
return Client::FIELD_CREDENTIALS; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @inheritdoc |
152
|
|
|
*/ |
153
|
34 |
|
public function getClientsIsConfidentialColumn(): string |
154
|
|
|
{ |
155
|
34 |
|
return Client::FIELD_IS_CONFIDENTIAL; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @inheritdoc |
160
|
|
|
*/ |
161
|
34 |
|
public function getClientsIsScopeExcessAllowedColumn(): string |
162
|
|
|
{ |
163
|
34 |
|
return Client::FIELD_IS_SCOPE_EXCESS_ALLOWED; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @inheritdoc |
168
|
|
|
*/ |
169
|
34 |
|
public function getClientsIsUseDefaultScopeColumn(): string |
170
|
|
|
{ |
171
|
34 |
|
return Client::FIELD_IS_USE_DEFAULT_SCOPE; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @inheritdoc |
176
|
|
|
*/ |
177
|
34 |
|
public function getClientsIsCodeGrantEnabledColumn(): string |
178
|
|
|
{ |
179
|
34 |
|
return Client::FIELD_IS_CODE_GRANT_ENABLED; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @inheritdoc |
184
|
|
|
*/ |
185
|
34 |
|
public function getClientsIsImplicitGrantEnabledColumn(): string |
186
|
|
|
{ |
187
|
34 |
|
return Client::FIELD_IS_IMPLICIT_GRANT_ENABLED; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @inheritdoc |
192
|
|
|
*/ |
193
|
34 |
|
public function getClientsIsPasswordGrantEnabledColumn(): string |
194
|
|
|
{ |
195
|
34 |
|
return Client::FIELD_IS_PASSWORD_GRANT_ENABLED; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @inheritdoc |
200
|
|
|
*/ |
201
|
34 |
|
public function getClientsIsClientGrantEnabledColumn(): string |
202
|
|
|
{ |
203
|
34 |
|
return Client::FIELD_IS_CLIENT_GRANT_ENABLED; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @inheritdoc |
208
|
|
|
*/ |
209
|
33 |
|
public function getClientsIsRefreshGrantEnabledColumn(): string |
210
|
|
|
{ |
211
|
33 |
|
return Client::FIELD_IS_REFRESH_GRANT_ENABLED; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @inheritdoc |
216
|
|
|
*/ |
217
|
33 |
|
public function getClientsCreatedAtColumn(): string |
218
|
|
|
{ |
219
|
33 |
|
return Client::FIELD_CREATED_AT; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @inheritdoc |
224
|
|
|
*/ |
225
|
33 |
|
public function getClientsUpdatedAtColumn(): string |
226
|
|
|
{ |
227
|
33 |
|
return Client::FIELD_UPDATED_AT; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @inheritdoc |
232
|
|
|
*/ |
233
|
66 |
|
public function getClientsScopesTable(): string |
234
|
|
|
{ |
235
|
66 |
|
return static::TABLE_CLIENTS_SCOPES; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @inheritdoc |
240
|
|
|
*/ |
241
|
32 |
|
public function getClientsScopesIdentityColumn(): string |
242
|
|
|
{ |
243
|
32 |
|
return static::CLIENTS_SCOPES_FIELD_ID; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @inheritdoc |
248
|
|
|
*/ |
249
|
37 |
|
public function getClientsScopesClientIdentityColumn(): string |
250
|
|
|
{ |
251
|
37 |
|
return Client::FIELD_ID; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @inheritdoc |
256
|
|
|
*/ |
257
|
34 |
|
public function getClientsScopesScopeIdentityColumn(): string |
258
|
|
|
{ |
259
|
34 |
|
return Scope::FIELD_ID; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @inheritdoc |
264
|
|
|
*/ |
265
|
68 |
|
public function getRedirectUrisTable(): string |
266
|
|
|
{ |
267
|
68 |
|
return static::TABLE_REDIRECT_URIS; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @inheritdoc |
272
|
|
|
*/ |
273
|
35 |
|
public function getRedirectUrisIdentityColumn(): string |
274
|
|
|
{ |
275
|
35 |
|
return RedirectUri::FIELD_ID; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @inheritdoc |
280
|
|
|
*/ |
281
|
38 |
|
public function getRedirectUrisClientIdentityColumn(): string |
282
|
|
|
{ |
283
|
38 |
|
return RedirectUri::FIELD_ID_CLIENT; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @inheritdoc |
288
|
|
|
*/ |
289
|
37 |
|
public function getRedirectUrisValueColumn(): string |
290
|
|
|
{ |
291
|
37 |
|
return RedirectUri::FIELD_VALUE; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @inheritdoc |
296
|
|
|
*/ |
297
|
33 |
|
public function getRedirectUrisCreatedAtColumn(): string |
298
|
|
|
{ |
299
|
33 |
|
return RedirectUri::FIELD_CREATED_AT; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @inheritdoc |
304
|
|
|
*/ |
305
|
33 |
|
public function getRedirectUrisUpdatedAtColumn(): string |
306
|
|
|
{ |
307
|
33 |
|
return RedirectUri::FIELD_UPDATED_AT; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @inheritdoc |
312
|
|
|
*/ |
313
|
66 |
|
public function getScopesTable(): string |
314
|
|
|
{ |
315
|
66 |
|
return static::TABLE_SCOPES; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @inheritdoc |
320
|
|
|
*/ |
321
|
39 |
|
public function getScopesIdentityColumn(): string |
322
|
|
|
{ |
323
|
39 |
|
return Scope::FIELD_ID; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @inheritdoc |
328
|
|
|
*/ |
329
|
35 |
|
public function getScopesDescriptionColumn(): string |
330
|
|
|
{ |
331
|
35 |
|
return Scope::FIELD_DESCRIPTION; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @inheritdoc |
336
|
|
|
*/ |
337
|
34 |
|
public function getScopesCreatedAtColumn(): string |
338
|
|
|
{ |
339
|
34 |
|
return Scope::FIELD_CREATED_AT; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @inheritdoc |
344
|
|
|
*/ |
345
|
34 |
|
public function getScopesUpdatedAtColumn(): string |
346
|
|
|
{ |
347
|
34 |
|
return Scope::FIELD_UPDATED_AT; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @inheritdoc |
352
|
|
|
*/ |
353
|
66 |
|
public function getTokensTable(): string |
354
|
|
|
{ |
355
|
66 |
|
return static::TABLE_TOKENS; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @inheritdoc |
360
|
|
|
*/ |
361
|
7 |
|
public function getTokensView(): string |
362
|
|
|
{ |
363
|
7 |
|
return static::VIEW_TOKENS; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @inheritdoc |
368
|
|
|
*/ |
369
|
6 |
|
public function getTokensViewScopesColumn(): string |
370
|
|
|
{ |
371
|
6 |
|
return Token::FIELD_SCOPES; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* @inheritdoc |
376
|
|
|
*/ |
377
|
38 |
|
public function getTokensIdentityColumn(): string |
378
|
|
|
{ |
379
|
38 |
|
return Token::FIELD_ID; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* @inheritdoc |
384
|
|
|
*/ |
385
|
42 |
|
public function getTokensIsEnabledColumn(): string |
386
|
|
|
{ |
387
|
42 |
|
return Token::FIELD_IS_ENABLED; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @inheritdoc |
392
|
|
|
*/ |
393
|
34 |
|
public function getTokensIsScopeModified(): string |
394
|
|
|
{ |
395
|
34 |
|
return Token::FIELD_IS_SCOPE_MODIFIED; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @inheritdoc |
400
|
|
|
*/ |
401
|
35 |
|
public function getTokensClientIdentityColumn(): string |
402
|
|
|
{ |
403
|
35 |
|
return Token::FIELD_ID_CLIENT; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @inheritdoc |
408
|
|
|
*/ |
409
|
39 |
|
public function getTokensUserIdentityColumn(): string |
410
|
|
|
{ |
411
|
39 |
|
return Token::FIELD_ID_USER; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* @inheritdoc |
416
|
|
|
*/ |
417
|
32 |
|
public function getTokensRedirectUriColumn(): string |
418
|
|
|
{ |
419
|
32 |
|
return Token::FIELD_REDIRECT_URI; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @inheritdoc |
424
|
|
|
*/ |
425
|
35 |
|
public function getTokensCodeColumn(): string |
426
|
|
|
{ |
427
|
35 |
|
return Token::FIELD_CODE; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @inheritdoc |
432
|
|
|
*/ |
433
|
42 |
|
public function getTokensValueColumn(): string |
434
|
|
|
{ |
435
|
42 |
|
return Token::FIELD_VALUE; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* @inheritdoc |
440
|
|
|
*/ |
441
|
34 |
|
public function getTokensTypeColumn(): string |
442
|
|
|
{ |
443
|
34 |
|
return Token::FIELD_TYPE; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* @inheritdoc |
448
|
|
|
*/ |
449
|
32 |
|
public function getTokensRefreshColumn(): string |
450
|
|
|
{ |
451
|
32 |
|
return Token::FIELD_REFRESH; |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* @inheritdoc |
456
|
|
|
*/ |
457
|
35 |
|
public function getTokensCodeCreatedAtColumn(): string |
458
|
|
|
{ |
459
|
35 |
|
return Token::FIELD_CODE_CREATED_AT; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* @inheritdoc |
464
|
|
|
*/ |
465
|
43 |
|
public function getTokensValueCreatedAtColumn(): string |
466
|
|
|
{ |
467
|
43 |
|
return Token::FIELD_VALUE_CREATED_AT; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* @inheritdoc |
472
|
|
|
*/ |
473
|
32 |
|
public function getTokensRefreshCreatedAtColumn(): string |
474
|
|
|
{ |
475
|
32 |
|
return Token::FIELD_REFRESH_CREATED_AT; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @inheritdoc |
480
|
|
|
*/ |
481
|
66 |
|
public function getTokensScopesTable(): string |
482
|
|
|
{ |
483
|
66 |
|
return static::TABLE_TOKENS_SCOPES; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* @inheritdoc |
488
|
|
|
*/ |
489
|
32 |
|
public function getTokensScopesIdentityColumn(): string |
490
|
|
|
{ |
491
|
32 |
|
return static::TOKENS_SCOPES_FIELD_ID; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* @inheritdoc |
496
|
|
|
*/ |
497
|
37 |
|
public function getTokensScopesTokenIdentityColumn(): string |
498
|
|
|
{ |
499
|
37 |
|
return Token::FIELD_ID; |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* @inheritdoc |
504
|
|
|
*/ |
505
|
36 |
|
public function getTokensScopesScopeIdentityColumn(): string |
506
|
|
|
{ |
507
|
36 |
|
return Scope::FIELD_ID; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* @inheritdoc |
512
|
|
|
*/ |
513
|
5 |
|
public function getUsersView(): ?string |
514
|
|
|
{ |
515
|
5 |
|
return static::VIEW_USERS; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* @inheritdoc |
520
|
|
|
*/ |
521
|
35 |
|
public function getUsersTable(): ?string |
522
|
|
|
{ |
523
|
35 |
|
return $this->usersTableName; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* @inheritdoc |
528
|
|
|
*/ |
529
|
35 |
|
public function getUsersIdentityColumn(): ?string |
530
|
|
|
{ |
531
|
35 |
|
return $this->usersIdColumn; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* @inheritdoc |
536
|
|
|
*/ |
537
|
9 |
|
public function getPassportView(): ?string |
538
|
|
|
{ |
539
|
9 |
|
return static::VIEW_PASSPORT; |
540
|
|
|
} |
541
|
|
|
} |
542
|
|
|
|