-
Notifications
You must be signed in to change notification settings - Fork 79
Experimental authenticator integration #8
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
Conversation
src/bundle/DependencyInjection/Compiler/AuthenticationProviderDecoratorCompilerPass.php
Outdated
Show resolved
Hide resolved
src/bundle/Security/Http/Authenticator/TwoFactorAuthenticator.php
Outdated
Show resolved
Hide resolved
f332257
to
4aa5c9f
Compare
I need to redirect the user to the 2fa form, while they're in that intermediate "2fa not finished" state. Until now, I've done this in the authentication listener: 2fa/src/bundle/Security/Http/Firewall/TwoFactorListener.php Lines 173 to 175 in 5d25f88
With authenticators I can't do this anymore, because authenticators can only generate a response when the login was successful/failed and not on every request. Would it be feasible to have my own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a very quick scan (I'll test somewhere next week, I'm very busy till tuesday), looks great afaics!
src/bundle/Security/Http/Authenticator/AuthenticatorDecorator.php
Outdated
Show resolved
Hide resolved
src/bundle/Security/Http/Authenticator/AuthenticatorDecorator.php
Outdated
Show resolved
Hide resolved
src/bundle/Security/Http/Authenticator/TwoFactorAuthenticator.php
Outdated
Show resolved
Hide resolved
From what I understand, this code is executed when all authenticators failed to authenticate the request? Would listening on the new |
@wouterj Thank you for the feedback, very helpful!
If you want to play around with it, the repository contains a little test application located in
No, the code needs to be executed as long as the user is in that intermediate state, when 2fa has not been completed yet. The purpose is to redirect the user to the 2fa form page, to ask for the 2fa code. The events you mentioned would only trigger when an authenticator was executed within the request. I was playing around with different solutions today and I'll most likely add a listener for I can give you an update as soon as I have something running that I believe is feasible. |
Ah, please note that the firewall listeners (like That would allow you to reuse the lazy firewall logic, which I think would make sense. |
Yea, would be cool to have an easier way to inject a listener into the firewall. Having a This whole authenticator experiment uncovered some bad design choices in my bundle and I figured there's better ways to do it. So I'm working on that at the moment ;) |
6c69228
to
cf00de5
Compare
faafc2a
to
0e9a73f
Compare
31f6631
to
38c9e99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested it in an application (sorry for the delay) and did a quick scan over the code.
I found one bug while testing: The new system has removed AnonymousToken (anonymous sessions now have no token). In order to whitelist pages to allow no token, a new special PUBLIC_ACCESS
attribute (AccessListener::PUBLIC_ACCESS
) was introduced.
This attribute is special: it is handled directly in Symfony's AccessListener
and not the access decision manager (it can only be used in access_control
).
The TwoFactorAccessDecider
needs a small update to also take this attribute into account as accessible. See wouterj@40699ef for a diff (feel free to copy the patch directly - I don't really care about attribution for this).
In case you want to test yourself, this is the diff I had to apply to test it in your great sample app: wouterj@749d046 (you also need the patch from symfony/symfony#37031, I just found this bug while testing this bundle)
src/bundle/Security/Http/Authenticator/Passport/TwoFactorPassport.php
Outdated
Show resolved
Hide resolved
src/bundle/Security/Http/Authenticator/Passport/TwoFactorPassport.php
Outdated
Show resolved
Hide resolved
src/bundle/DependencyInjection/Factory/Security/TwoFactorFactory.php
Outdated
Show resolved
Hide resolved
…wouterj) This PR was merged into the 5.1 branch. Discussion ---------- [Security] Fixed PUBLIC_ACCESS in authenticated sessions | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Found while testing scheb/2fa#8, sorry for not spotting it before the stable release 😞 Currently, authenticated users are denied access for pages that have `PUBLIC_ACCESS` set, as this attribute is only checked when no token was set. It should be checked for both cases. Commits ------- 0ac530f Also check PUBLIC_ACCESS for authenticated tokens
Thanks for looking into it. As you can see from the many force-pushes, I'm still messing around a lot in the code, but I consider the implementation now relatively stable. Good that you mentioned |
Almost done, some test cases are still missing :) |
Very cool to see this merged. 🎈 Thanks for your hard work! It's one of the first major security bundles with support in their master branch |
Thanks for your help to make this work! I'll release a v5 with authenticators support soon. |
Closes #5