-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
fix(auth): Unify ZMI, HTML form, and API login #1141
Conversation
@rpatterson thanks for creating this Pull Request and help improve Plone! To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass. Whenever you feel that the pull request is ready to be tested, either start all jenkins jobs pull requests by yourself, or simply add a comment in this pull request stating:
With this simple comment all the jobs will be started automatically. Happy hacking! |
25d8e4d
to
94abc85
Compare
@jenkins-plone-org please run jobs |
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.
Overall LGTM, curious about the use case that triggered this.
@alecghica the feature you told me several weeks ago in the Volto Team meeting was different, right?
@buchi @lukasgraf @tisto It would be great if you could also take a look! Thanks!
@rpatterson, time ago I started with https://github.com/plone/plone.restapi/tree/mamico/ext-login that probably could |
It's related to that. |
94abc85
to
8fb6eb2
Compare
I believe I've addressed all the feedback, @tiberiuichim @tisto. LMK if I missed anything. Otherwise, what are the next steps? I assume a review approval. After that, for this project is the merge button something I push? Any follow up steps expected of me? |
@jenkins-plone-org please run jobs |
Thanks for reaching out, @mamico! First, a minor nit pick, it looks like your 2nd commit is just a line ending change for the 1st commit so I assume they should be squashed together? Is the Proceeding from there assuming that setting that cookie has the desired effect in the Volto components, then I would say your event subscriber code should be converted to a I haven't thought about your code in depth as I would for a PR review so just request a review from me in a PR if you'd like a more detailed evaluation. One potential issue jumps out at me, how would your code set the same JWT token in both the cookie and return it in the JSON response to a login |
@rpatterson first of all, thanks for your PR and the time you put into discussing our nitpicking comments. The PR looks good to me. I'd just like to give it a shot locally and maybe @buchi and/or @lukasgraf to have a second look. Then we are good to merge and I can do a release right away. There is no further action from your side required I guess. @buchi @lukasgraf let us know if you want this fix in plone.restapi 7.x. Since we started the new Plone 5.2/Python3 branch (8.x.x) we have to decide if we want this fix there as well. |
K, works for me. ;-) Quick caveat, I just tuned into the CI failure from the run I kicked off after my latest push. The output doesn't say much to me so I can't even argue whether or not it's related to my changes. I've never gotten to fluency with Robot tests so it may take me time to understand this failure. OTOH, I've wanted to achieve fluency there so if someone thinks this is related, give me some hints and I'll get to it! Otherwise I'll assume this PR is in others hands until I hear otherwise. |
@tisto would be great to have it for plone.restapi 7.x. |
@rpatterson It's common for some robot tests to fail on Jenkins unrelated to your PR. When this happens, you have to restart the job that failed. To do this, access the job that failed, click on "Login" to authenticate, click on the menu "job number" -> Retry |
@rpatterson thanks,
AFAIK, Volto uses the token in the
Good point, I'll try to think about it...
Sorry, I don't understand this last point ... the main picture is: whichever way you authenticate with a legacy plone pas plugin, if correctly the IUserLoggedInEvent event will be called, this code will return to the user a valid auth_token cookie, this is all Volto needs for subsequent calls to the backend. |
Thanks! I didn't know I could log into Plone Jenkins. I've restarted it. To put in my $0.02 that no one asked for, I think an intermittent test is often worse than no test. It frustrates the community of developers and trains them to ignore tests over time. We want our tests to help developers fall in love with testing. This goes double for CI. Does Robot Framework have an equivalent of Python's |
To clarify, @mamico. Doesn't the login API endpoint view from |
@rpatterson. It's the same token, in fact I use the same |
Apologies for the back and forth, @mamico. Maybe you could create a PR, label it
Yeah, I saw that, but I thought when I read the |
Just a quick reminder, is anyone able to review? (CC: @tisto, @buchi, @sneridagh, @lukasgraf) |
This was created for me locally and I assume it's just a recent/new artifact and should just be ignored.
Fix some behavior in the PAS plugin that treated API login requests differently than classic HTML form login requests, namely that the POST'ed login credentials weren't extracted and authenticated like they are when the classic HTML login form is POST'ed. IMO, the root cause here was a minor case of not actually fulfilling the PAS contract. In the case of the classic HTML login form, it's another PAS plugin that extracts the POST'ed credentials, but since the API login POST submits JSON, it has to be the JWT plugin that extracts them. Also reproduce the same handling that the classic Plone HTML login form does after login has succeeded. This includes setting the classic HTML login form cookie so that authenticating to the API also authenticates the user to the classic HTML UI (as well as the ZMI when the user has the `Manager` role). But it also includes other core Plone login behavior. In the case of Volto, there's one more edge case remaining. Namely, if the browser is already authenticated such as by having previously submitted the classic HTML login form, a fresh load of the Volto UI will still show them as logged out even though their API requests succeed as authenticated. I assume this is a problem in the React component state that doesn't do an actual API check to see if the user is already authenticated.
8fb6eb2
to
6d97fa4
Compare
@jenkins-plone-org please run jobs |
@rpatterson @avoinea @tiberiuichim @alecghica we run into some issues with this fix in one of our main Volto sites. The problem can be reproduced as follows:
-> when you login again (e.g. with another user) you end up with mixed auth that does all kinds of strange things. @sneridagh tried to fix this issue recently but it seems this did not do the trick. I am considering reverting this PR and do another plone.restapi release to fix this (IMHO serious problem), to give us some time to investigate the issue. Opinions? |
I think the problem is that the Volto part is missing, which should have logged you out of Plone as well. I think a simple Volto fix could be implemented, to delete the |
@tiberiuichim this is exactly what @sneridagh did if I am not mistaken. This did not solve the issue though. :/ |
@tisto It didn't solve all the issues within Volto, but I think it will solve the issue you described above. |
@avoinea @tiberiuichim this still happens in latest Volto. Do the following:
The ac_ cookie is still present (on both): |
@tisto I know, the |
I think I've resolved all the outstanding issues brought up here in #1303, @avoinea @tisto @tiberiuichim. LMK if I'm missing something! |
Fix some behavior in the PAS plugin that treated API login requests differently than
classic HTML form login requests, namely that the POST'ed login credentials weren't
extracted and authenticated like they are when the classic HTML login form is POST'ed.
IMO, the root cause here was a minor case of not actually fulfilling the PAS plugin
interface. In the case of the classic HTML login form, it's another PAS plugin that
extracts the POST'ed credentials, but since the API login POST submits JSON, it has to
be the JWT plugin that extracts them.
Also reproduce the same handling that the classic Plone HTML login form does after login
has succeeded. This includes setting the classic HTML login form cookie so that
authenticating to the API also authenticates the user to the classic HTML UI (as well as
the ZMI when the user has the
Manager
role). But it also includes other core Plonelogin behavior.
In the case of Volto, there's one more edge case remaining. Namely, if the browser is
already authenticated such as by having previously submitted the classic HTML login
form, a fresh load of the Volto UI will still show them as logged out even though their
API requests succeed as authenticated. I assume this is a problem in the React
component state that doesn't do an actual API check to see if the user is already
authenticated and if I'm right a fix for that can't be included here.
This is my first Volto-adjacent PR. Please LMK what parts of etiquette I may be unaware
of. Also please pick all the nits possible so I can learn how to better form PRs for
the Volto project going forward. IOW, let me have it! ;-)