File tree 3 files changed +51
-2
lines changed
3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
return [
6
6
7
+ /*
8
+ |--------------------------------------------------------------------------
9
+ | The router prefix
10
+ |--------------------------------------------------------------------------
11
+ |
12
+ | This will be the prefix for the `/csrf-header` GET route.
13
+ | E.g. prefix = 'api' => than you can get the header token via: `/api/csrf-header
14
+ |
15
+ */
16
+
17
+ 'prefix ' => env ('STATELESS_PREFIX ' , 'api ' ),
18
+
7
19
/*
8
20
|--------------------------------------------------------------------------
9
21
| Header Cookie Name
16
28
*/
17
29
18
30
'header ' => env (
19
- 'SESSION_HEADER ' ,
20
- Str::upper (Str::slug (env ('APP_NAME ' , 'laravel ' ), '- ' ). '-session ' )
31
+ 'STATELESS_SESSION_HEADER ' ,
32
+ Str::upper (Str::slug (env ('APP_NAME ' , 'laravel ' ), '- ' ) . '-session ' )
21
33
),
22
34
23
35
];
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Binarcode \LaravelStatelessSession \Http \Controllers ;
4
+
5
+ use Illuminate \Http \Response ;
6
+
7
+ class CsrfHeaderController
8
+ {
9
+ /**
10
+ * Return an empty response simply to trigger the storage of the CSRF cookie in the browser.
11
+ *
12
+ * @return \Illuminate\Http\Response
13
+ */
14
+ public function show ()
15
+ {
16
+ return new Response ('' , 204 );
17
+ }
18
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace Binarcode \LaravelStatelessSession ;
4
4
5
+ use Binarcode \LaravelStatelessSession \Http \Middleware \StartStatelessSession ;
5
6
use Illuminate \Support \ServiceProvider ;
7
+ use Illuminate \Support \Facades \Route ;
8
+ use Binarcode \LaravelStatelessSession \Http \Controllers \CsrfHeaderController ;
6
9
7
10
class LaravelStatelessSessionServiceProvider extends ServiceProvider
8
11
{
@@ -11,6 +14,8 @@ class LaravelStatelessSessionServiceProvider extends ServiceProvider
11
14
*/
12
15
public function boot ()
13
16
{
17
+ $ this ->defineRoutes ();
18
+
14
19
if ($ this ->app ->runningInConsole ()) {
15
20
$ this ->publishes ([
16
21
__DIR__ .'/../config/config.php ' => config_path ('stateless.php ' ),
@@ -44,4 +49,18 @@ protected function registerSessionManager()
44
49
return new SessionManager ($ app );
45
50
});
46
51
}
52
+
53
+ protected function defineRoutes ()
54
+ {
55
+ if ($ this ->app ->routesAreCached ()) {
56
+ return ;
57
+ }
58
+
59
+ Route::group (['prefix ' => config ('stateless.prefix ' , 'api ' )], function () {
60
+ Route::get (
61
+ '/csrf-header ' ,
62
+ CsrfHeaderController::class.'@show '
63
+ )->middleware (StartStatelessSession::class);
64
+ });
65
+ }
47
66
}
You can’t perform that action at this time.
0 commit comments