This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ class Kernel extends HttpKernel
54
54
protected $ routeMiddleware = [
55
55
'auth ' => \App \Http \Middleware \Authenticate::class,
56
56
'auth.basic ' => \Illuminate \Auth \Middleware \AuthenticateWithBasicAuth::class,
57
+ 'basic ' => \App \Http \Middleware \BasicAuthMiddleware::class,
57
58
'bindings ' => \Illuminate \Routing \Middleware \SubstituteBindings::class,
58
59
'cache.headers ' => \Illuminate \Http \Middleware \SetCacheHeaders::class,
59
60
'can ' => \Illuminate \Auth \Middleware \Authorize::class,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Http \Middleware ;
4
+
5
+ use Closure ;
6
+
7
+ class BasicAuthMiddleware
8
+ {
9
+ /**
10
+ * Handle an incoming request.
11
+ *
12
+ * @param \Illuminate\Http\Request $request
13
+ * @param \Closure $next
14
+ * @return mixed
15
+ */
16
+ public function handle ($ request , Closure $ next , ...$ args )
17
+ {
18
+ $ correct_user = $ args [0 ];
19
+ $ correct_password = $ args [1 ];
20
+ switch (true ) {
21
+ case !isset ($ _SERVER ['PHP_AUTH_USER ' ], $ _SERVER ['PHP_AUTH_PW ' ]):
22
+ case $ _SERVER ['PHP_AUTH_USER ' ] !== $ correct_user :
23
+ case $ _SERVER ['PHP_AUTH_PW ' ] !== $ correct_password :
24
+ header ('WWW-Authenticate: Basic realm="Access denied" ' );
25
+ header ('Content-Type: text/plain; charset=utf-8 ' );
26
+ die ('Not authorized ' );
27
+ }
28
+ return $ next ($ request );
29
+ }
30
+ }
Original file line number Diff line number Diff line change 16
16
Route::get ('/ ' , function () {
17
17
return view ('welcome ' );
18
18
});
19
+
20
+ Route::group (['middleware ' => ['basic:hoge,fuga ' ]], function () {
21
+ Route::get ('/basic ' , function () {
22
+ return "Authorized " ;
23
+ });
24
+ });
You can’t perform that action at this time.
0 commit comments