-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayground-auth.php
273 lines (231 loc) · 8.05 KB
/
playground-auth.php
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
<?php
declare(strict_types=1);
return [
/*
|--------------------------------------------------------------------------
| Packages
|--------------------------------------------------------------------------
|
| PLAYGROUND_AUTH_PACKAGES may be used to load abilities from other packages.
|
| PLAYGROUND_AUTH_REQUIRE_PACKAGE_ABILITIES is enabled by default. When
| using token abilities, this value ensures that `playground-auth` is
| included in `PLAYGROUND_AUTH_PACKAGES` if omitted in the .env.
|
| PLAYGROUND_AUTH_DEBUG Requires config(app.debug) to be true to display logs.
*/
'packages' => is_string(env('PLAYGROUND_AUTH_PACKAGES', 'playground-auth')) ? array_map(
'trim',
explode(',', env('PLAYGROUND_AUTH_PACKAGES', 'playground-auth'))
) : [],
'require' => [
/**
* @var bool package_abilities By default, require
*/
'package_abilities' => (bool) env('PLAYGROUND_AUTH_REQUIRE_PACKAGE_ABILITIES', true),
],
/**
* @var bool debug Enable authentication debugging messages.
*/
'debug' => (bool) env('PLAYGROUND_AUTH_DEBUG', false),
// 'debug' => (bool) env('PLAYGROUND_AUTH_DEBUG', true),
/*
|--------------------------------------------------------------------------
| Loading
|--------------------------------------------------------------------------
|
| PLAYGROUND_AUTH_LOAD_COMMANDS enables Console\Commands\HashPassword
|
| PLAYGROUND_AUTH_LOAD_TRANSLATIONS loads translations in /lang
|
*/
'load' => [
'commands' => (bool) env('PLAYGROUND_AUTH_LOAD_COMMANDS', true),
'translations' => (bool) env('PLAYGROUND_AUTH_LOAD_TRANSLATIONS', true),
],
/*
|--------------------------------------------------------------------------
| Redirects
|--------------------------------------------------------------------------
|
| PLAYGROUND_AUTH_REDIRECT may be disabled to show an error page instead.
*/
/**
* @var ?string redirect Specify for redirect()->guest($redirect)
*/
'redirect' => env('PLAYGROUND_AUTH_REDIRECT', 'login'),
// 'redirect' => null,
/*
|--------------------------------------------------------------------------
| Policies
|--------------------------------------------------------------------------
|
| ModelPolicy supports multiple security implementations.
|
| Options for Sanctum:
| - PLAYGROUND_AUTH_USER_PRIVILEGES - allow saving privileges in the user model.
| - PLAYGROUND_AUTH_VERIFY === sanctum
|
| Verification:
| - admin: $user->isAdmin()
| - policy: $user->can()
| - privileges: $user->hasPrivilege()
| - roles: $user->hasRole()
| - sanctum: $user->currentAccessToken()->can()
| - user: ! empty($user)
*/
/**
* @var string verify admin|user|policy|privileges|roles|sanctum
*/
'verify' => env('PLAYGROUND_AUTH_VERIFY', 'sanctum'),
/**
* @var bool sanctum Enable Sanctum
*/
'sanctum' => (bool) env('PLAYGROUND_AUTH_SANCTUM', true),
/**
* @var bool hasPrivilege Enable if the user model has $user->hasPrivilege($privilege)
*/
'hasPrivilege' => (bool) env('PLAYGROUND_AUTH_HAS_PRIVILEGE', false),
/**
* @var bool hasPrivilege Enable if the user model has the attribute User::$privileges
*/
'userPrivileges' => (bool) env('PLAYGROUND_AUTH_USER_PRIVILEGES', false),
/**
* @var bool hasRole Enable if the user model has $user->hasRole($role)
*/
'hasRole' => (bool) env('PLAYGROUND_AUTH_HAS_ROLE', false),
/**
* @var bool userRole Enable if the user model has the attribute User::$role
*/
'userRole' => (bool) env('PLAYGROUND_AUTH_USER_ROLE', false),
/**
* @var bool userRoles Enable if the user model has the attribute User::$roles
*/
'userRoles' => (bool) env('PLAYGROUND_AUTH_USER_ROLES', false),
/**
* @var string canDefault The default privilege for Auth\Can::class checks.
* A value is required for Sanctum checks.
*/
'canDefault' => env('PLAYGROUND_AUTH_CAN_DEFAULT', 'app'),
/*
|--------------------------------------------------------------------------
| Token configuration
|--------------------------------------------------------------------------
|
| Enabling Sanctum provides token and API key support.
|
| TODO We could/shoud add Passport support.
|
*/
'token' => [
/**
* @var string abilities merge|user
*/
'abilities' => env('PLAYGROUND_AUTH_TOKEN_ABILITIES', 'merge'),
/**
* @var ?string expires Set expires to null to allow tokens to live forever.
*/
'expires' => env('PLAYGROUND_AUTH_TOKEN_EXPIRES', 'tomorrow midnight'),
/**
* @var string name The token name.
*/
'name' => env('PLAYGROUND_AUTH_TOKEN_NAME', 'app'),
/**
* @var bool listed Use the listed admins and managers in this configuration.
*/
'listed' => (bool) env('PLAYGROUND_AUTH_TOKEN_LISTED', false),
/**
* @var bool roles Check the user role(s) for applying abilities.
*/
'roles' => (bool) env('PLAYGROUND_AUTH_TOKEN_ROLES', false),
/**
* @var bool privileges Allow the attribute User::$privileges to be used for authorization.
*/
'privileges' => (bool) env('PLAYGROUND_AUTH_TOKEN_PRIVILEGES', false),
/**
* @var bool sanctum The token will use Sanctum.
*/
'sanctum' => (bool) env('PLAYGROUND_AUTH_TOKEN_SANCTUM', true),
/**
* @var bool session Save the token in the session.
*/
'session' => (bool) env('PLAYGROUND_AUTH_TOKEN_SESSION', false),
/**
* @var string session_name The session name for the token.
*/
'session_name' => env('PLAYGROUND_AUTH_TOKEN_SESSION_NAME', 'sanctum'),
/**
* @var bool transient Allow transient tokens in policies.
*/
'transient' => (bool) env('PLAYGROUND_AUTH_TOKEN_TRANSIENT', false),
],
/*
|--------------------------------------------------------------------------
| Listed admins and managers
|--------------------------------------------------------------------------
|
| Allow specifying a set of admins and/or managers.
|
*/
/**
* @var array<int, string> admins Provide an array of email addresses for admin privileges.
*/
'admins' => [
// '[email protected]',
// '[email protected]',
// '[email protected]',
],
/**
* @var array<int, string> managers Provide an array of email addresses for manager privileges.
*/
'managers' => [
// '[email protected]',
],
/*
|--------------------------------------------------------------------------
| Abilities
|--------------------------------------------------------------------------
|
| Root: has all privileges, where applicable.
|
| Admins: have wildcard access, at top level of resources.
|
| Manager: Has wildcard access at the model level.
|
| User: Has specific privileges and no wildcards.
|
| Guest: Specify `deny` for no privileges.
|
*/
'abilities' => [
'root' => [
'*',
],
'admin' => [
'app:*',
'playground:*',
'playground-auth:*',
],
'manager' => [
'app:view',
'playground:view',
'playground-auth:logout',
'playground-auth:reset-password',
],
'user' => [
'app:view',
'playground:view',
'playground-auth:logout',
'playground-auth:reset-password',
],
'guest' => [
'deny',
],
// 'guest' => [
// 'app:view',
// 'playground:view',
// 'playground-auth:logout',
// 'playground-auth:reset-password',
// ],
],
];