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

[5.7] Add guard to authentication events #25261

Merged
merged 2 commits into from
Aug 20, 2018
Merged

[5.7] Add guard to authentication events #25261

merged 2 commits into from
Aug 20, 2018

Conversation

Propaganistas
Copy link
Contributor

I'm running into a situation where I need to fire some actions after logout, but only for a particular guard.

Currently there's no straightforward way to determine which guard was responsible for firing one of the authentication events.

@deleugpn
Copy link
Contributor

deleugpn commented Aug 19, 2018

Why not pass the whole Guard context ($this) instead of just the name ($this->name)?
Also, this should have some tests.

@GrahamCampbell GrahamCampbell changed the title Add guard to authentication events [5.7] Add guard to authentication events Aug 19, 2018
@Propaganistas
Copy link
Contributor Author

Propaganistas commented Aug 19, 2018

Fair point about passing the whole Guard instance. I needed to add an additional getGuardName() method in order to easily get hold of the guard's config name. In this light, since the framework only fires the events in it's SessionGuard, I thought it might be appropriate to typehint $guard as the StatefulGuard contract.

Regarding tests: I couldn't find any checking the constructor arguments of the events.

@taylorotwell taylorotwell merged commit 76da465 into laravel:5.7 Aug 20, 2018
@rodrigopedra
Copy link
Contributor

rodrigopedra commented Sep 10, 2018

Passing the whole guard breaks any queued listeners as the Guards in general (SessionGuard for instance) relies on closures (see the request, provider and events properties, each have closure-based resolvers).

I have a queued listener that updates a timestamp in the user's record whenever the Login event is fired. Use it in every project (show a last logged at timestamp).

To migrate some of them to Laravel 5.7 I had to make this listener synchronous (remove the ShouldQueue interface) as with the change this PR introduces it throws an Serialization of closures is not allowed exception.

I have some suggestions:

  1. Revert to the old behavior

  2. Pass only the guard name to the event, as it was originally intended in this PR

  3. Document it as a breaking change in the upgrade guide
    If you are listening for Authentication Events you should not use queued listeners anymore...

I can submit a PR for any of these alternatives as soon as we have a decision

@devcircus
Copy link
Contributor

If this is really breaking in this way, it needs to be reverted. We can't say "no queued listeners" when listening for authentication events.

@rodrigopedra
Copy link
Contributor

I submitted issue #25566 with steps to reproduce. Also I imagine a new issue would get more attention than a comment on a merged PR

@deleugpn
Copy link
Contributor

Given your complete knowledge on the issue, I think it would be beneficial if you open a PR with the original intent as it might solve the issue while still offering the original feature.

@rodrigopedra
Copy link
Contributor

@deleugpn It seems the best option to me, but it would be a breaking change on a newly released version... I will send it anyway and maybe we can decide for a better approach later

@deleugpn
Copy link
Contributor

I think we can advocate that this was a major breakage because it broke the feature. I would argue in favour of the breaking change given the state of the feature.
It's even better to do it now while 5.7 is a fresh release.
Perhaps even better would be to try and write a test that prevents this type of issue from happening again.

@rodrigopedra
Copy link
Contributor

Sent the #25568 PR, working on the tests now.

@rodrigopedra
Copy link
Contributor

Ping @Propaganistas , please check if PR #25568 breaks your workflow

@Propaganistas
Copy link
Contributor Author

Thanks for the heads up.

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

Successfully merging this pull request may close these issues.

5 participants