Skip to content

Commit

Permalink
allow full customization of authentication pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 10, 2020
1 parent 02a86b2 commit 6c36b08
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/Fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

class Fortify
{
/**
* The callback that is responsible for building the authentication pipeline array, if applicable.
*
* @var callable|null
*/
public static $loginThroughCallback;

/**
* Indicates if Fortify routes will be registered.
*
Expand Down Expand Up @@ -136,6 +143,17 @@ public static function requestPasswordResetLinkView($view)
});
}

/**
* Register a callback that is responsible for building the authentication pipeline array.
*
* @param callable $callback
* @return void
*/
public static function loginThrough(callable $callback)
{
static::$loginThroughCallback = $callback;
}

/**
* Register a class / callback that should be used to create new users.
*
Expand Down
30 changes: 27 additions & 3 deletions src/Http/Controllers/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Laravel\Fortify\Contracts\LoginResponse;
use Laravel\Fortify\Contracts\LoginViewResponse;
use Laravel\Fortify\Contracts\LogoutResponse;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Requests\LoginRequest;

class AuthenticatedSessionController extends Controller
Expand Down Expand Up @@ -54,14 +55,37 @@ public function create(Request $request): LoginViewResponse
*/
public function store(LoginRequest $request)
{
return $this->loginPipeline($request)->then(function ($request) {
return app(LoginResponse::class);
});
}

/**
* Get the authentication pipeline instance.
*
* @param \Laravel\Fortify\Http\Requests\LoginRequest $request
* @return \Illuminate\Pipeline\Pipeline
*/
protected function loginPipeline(LoginRequest $request)
{
if (Fortify::$loginThroughCallback) {
return (new Pipeline(app()))->send($request)->through(array_filter(
call_user_func(Fortify::$loginThroughCallback, $request)
));
}

if (is_array(config('fortify.pipelines.login'))) {
return (new Pipeline(app()))->send($request)->through(array_filter(
config('fortify.pipelines.login')
));
}

return (new Pipeline(app()))->send($request)->through(array_filter([
config('fortify.limiters.login') ? null : EnsureLoginIsNotThrottled::class,
RedirectIfTwoFactorAuthenticatable::class,
AttemptToAuthenticate::class,
PrepareAuthenticatedSession::class,
]))->then(function ($request) {
return app(LoginResponse::class);
});
]));
}

/**
Expand Down

0 comments on commit 6c36b08

Please sign in to comment.