Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Adds Validated auth event #31357

Merged
merged 4 commits into from Feb 5, 2020
Merged

[6.x] Adds Validated auth event #31357

merged 4 commits into from Feb 5, 2020

Conversation

@DarkGhostHunter
Copy link
Contributor

DarkGhostHunter commented Feb 5, 2020

This PR adds the Validated auth event. This event is fired after a User is retrieved from the User Provider and properly validated, but before the Login event and logic:

image

This allows any package to intercede on the authentication after a successful attempt but before login logic. As you can see, the Login event is fired after all login logic is already executed.

image

This allows to intercede into the authentication without having to retrieve the user two times. For example, we can now run complex logic and deny further authentication after the user is validated using a Listener:

public function handle(Validated $event)
{
    if ($event->user->isDynamicallyLocked()) {
        response()->view('auth.locked', ['user' => $event->user])->throwResponse();
    }
}

This is handy, for example, when we need to filter what Users can continue to authenticate depending on a complex prerequisites (like a relation value, or an external API response, whatever) which we cannot set in the LoginController, and without having to edit the SessionGuard or macro it.

Please comment so I don't feel alone. Thanks.

Project update.
…Good time to remember to code responsibly!)
@taylorotwell taylorotwell merged commit 5aead14 into laravel:6.x Feb 5, 2020
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@DarkGhostHunter

This comment has been minimized.

Copy link
Contributor Author

DarkGhostHunter commented Feb 5, 2020

I'll comment myself. Good job.

@driesvints

This comment has been minimized.

Copy link
Member

driesvints commented Feb 10, 2020

@DarkGhostHunter thanks man 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.