File tree Expand file tree Collapse file tree 5 files changed +68
-2
lines changed Expand file tree Collapse file tree 5 files changed +68
-2
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
declare (strict_types=1 );
3
3
4
- namespace App \Middlewares ;
4
+ namespace Haku \ Delegation \Middlewares ;
5
5
6
6
/* @note Deny direct file access */
7
7
if (defined ('HAKU_ROOT_PATH ' ) === false ) exit ;
Original file line number Diff line number Diff line change 1
1
<?php
2
2
declare (strict_types=1 );
3
3
4
- namespace App \Middlewares ;
4
+ namespace Haku \ Delegation \Middlewares ;
5
5
6
6
/* @note Deny direct file access */
7
7
if (defined ('HAKU_ROOT_PATH ' ) === false ) exit ;
Original file line number Diff line number Diff line change @@ -282,11 +282,17 @@ function parseRouteAttributes(
282
282
283
283
/**
284
284
* Converts middlewares from "foo" to "App\Middlewares\Foo"
285
+ * And @foo to "Haku\Delegation\Middlewares\Foo"
285
286
*/
286
287
function normalizeMiddlewarePathName (string $ unresolved ): string
287
288
{
288
289
$ namespace = ['App ' , 'Middlewares ' ];
289
290
291
+ if (\str_starts_with (needle: '@ ' , haystack: $ unresolved ))
292
+ {
293
+ $ namespace = ['Haku ' , 'Delegation ' , 'Middlewares ' ];
294
+ }
295
+
290
296
$ parts = explode ('/ ' , $ unresolved );
291
297
$ parts = array_map (fn ($ part ) => ucfirst (camelCaseFromSnakeCase ($ part )), $ parts );
292
298
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace Haku \Jwt ;
5
+
6
+ /* @note Deny direct file access */
7
+ if (defined ('HAKU_ROOT_PATH ' ) === false ) exit ;
8
+
9
+ class Authorization
10
+ {
11
+
12
+ public static function make (int $ identifier , string $ scope ): string
13
+ {
14
+ return encodeToken ([
15
+ 'identifier ' => $ identifier ,
16
+ 'scope ' => $ scope ,
17
+ ]);
18
+ }
19
+
20
+ public static function verifyIdentifier (int $ identifier ): bool
21
+ {
22
+ $ token = currentToken ();
23
+
24
+ if (!$ token )
25
+ {
26
+ return false ;
27
+ }
28
+
29
+ $ payload = $ token ->getPayload ();
30
+
31
+ if ($ payload ['identifier ' ] === $ identifier )
32
+ {
33
+ return true ;
34
+ }
35
+
36
+ return false ;
37
+ }
38
+
39
+ public static function verifyScope (array $ allowedScopes ): bool
40
+ {
41
+ $ token = currentToken ();
42
+
43
+ if (!$ token )
44
+ {
45
+ return false ;
46
+ }
47
+
48
+ $ payload = $ token ->getPayload ();
49
+
50
+ if (
51
+ count ($ allowedScopes ) > 0 &&
52
+ in_array ($ payload ['scope ' ], $ allowedScopes )
53
+ ) {
54
+ return true ;
55
+ }
56
+
57
+ return false ;
58
+ }
59
+
60
+ }
You can’t perform that action at this time.
0 commit comments