Skip to content

Commit 6c36b08

Browse files
committed
allow full customization of authentication pipeline
1 parent 02a86b2 commit 6c36b08

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/Fortify.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
class Fortify
1818
{
19+
/**
20+
* The callback that is responsible for building the authentication pipeline array, if applicable.
21+
*
22+
* @var callable|null
23+
*/
24+
public static $loginThroughCallback;
25+
1926
/**
2027
* Indicates if Fortify routes will be registered.
2128
*
@@ -136,6 +143,17 @@ public static function requestPasswordResetLinkView($view)
136143
});
137144
}
138145

146+
/**
147+
* Register a callback that is responsible for building the authentication pipeline array.
148+
*
149+
* @param callable $callback
150+
* @return void
151+
*/
152+
public static function loginThrough(callable $callback)
153+
{
154+
static::$loginThroughCallback = $callback;
155+
}
156+
139157
/**
140158
* Register a class / callback that should be used to create new users.
141159
*

src/Http/Controllers/AuthenticatedSessionController.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Laravel\Fortify\Contracts\LoginResponse;
1414
use Laravel\Fortify\Contracts\LoginViewResponse;
1515
use Laravel\Fortify\Contracts\LogoutResponse;
16+
use Laravel\Fortify\Fortify;
1617
use Laravel\Fortify\Http\Requests\LoginRequest;
1718

1819
class AuthenticatedSessionController extends Controller
@@ -54,14 +55,37 @@ public function create(Request $request): LoginViewResponse
5455
*/
5556
public function store(LoginRequest $request)
5657
{
58+
return $this->loginPipeline($request)->then(function ($request) {
59+
return app(LoginResponse::class);
60+
});
61+
}
62+
63+
/**
64+
* Get the authentication pipeline instance.
65+
*
66+
* @param \Laravel\Fortify\Http\Requests\LoginRequest $request
67+
* @return \Illuminate\Pipeline\Pipeline
68+
*/
69+
protected function loginPipeline(LoginRequest $request)
70+
{
71+
if (Fortify::$loginThroughCallback) {
72+
return (new Pipeline(app()))->send($request)->through(array_filter(
73+
call_user_func(Fortify::$loginThroughCallback, $request)
74+
));
75+
}
76+
77+
if (is_array(config('fortify.pipelines.login'))) {
78+
return (new Pipeline(app()))->send($request)->through(array_filter(
79+
config('fortify.pipelines.login')
80+
));
81+
}
82+
5783
return (new Pipeline(app()))->send($request)->through(array_filter([
5884
config('fortify.limiters.login') ? null : EnsureLoginIsNotThrottled::class,
5985
RedirectIfTwoFactorAuthenticatable::class,
6086
AttemptToAuthenticate::class,
6187
PrepareAuthenticatedSession::class,
62-
]))->then(function ($request) {
63-
return app(LoginResponse::class);
64-
});
88+
]));
6589
}
6690

6791
/**

0 commit comments

Comments
 (0)