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

Tprod 296 Authentication refactoring needed for Symfony 5 #11057

Merged
merged 25 commits into from Sep 9, 2022

Conversation

escopecz
Copy link
Sponsor Member

@escopecz escopecz commented Apr 7, 2022

Q A
Bug fix? (use the a.b branch) [ ]
New feature/enhancement? (use the a.x branch) [x]
Deprecations? [ ]
BC breaks? (use the c.x branch) [x]
Automated tests included? [x]
Related user documentation PR URL
Related developer documentation PR URL
Issue(s) addressed Fixes https://mautic.atlassian.net/browse/TPROD-296

Description:

I started with this by looking what is the AuthenticationListener used for and found last changes coming from #9837 so I got an impression it is used for Oauth2 and wrote a test for it. It turns out it's not that related and the AuthenticationListener that needed refactoring is actually used for user login and SSO. Anyway, the test for Oauth2 is useful to have.

The changes needed to get rid of the deprecated ListenerInterface are actually nicely described in https://stackoverflow.com/questions/56438177/deprecated-the-listenerinterface-turn-your-listeners-into-callables-instead and if I'd follow that instead of trying to figure out the usage from git history and the code then it would save a lot of time.

This PR also changes configuration for the "anonymous" security option from true to 'lazy'. That is a new option since Symfony 4.4 described as

The lazy anonymous mode prevents the session from being started if there is no need for authorization

So I was hoping it will stop creating session cookies on those routes but it behaves the same as before.

Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)
  2. Test that you can log in to the instance.
  3. Test accessing an API endpoint with Oauth 2 by following steps in TPROD-170: Enabling 2-legged authentication for Mautic #9837
  4. If you have that option, test also SSO login.

@cla-bot cla-bot bot added the cla-signed The PR contributors have signed the contributors agreement label Apr 7, 2022
@escopecz escopecz added the bc-break A BC break PR for major release milestones only label Apr 8, 2022
@escopecz escopecz added this to the 5.0-alpha milestone Apr 8, 2022
@escopecz escopecz added the ready-to-test PR's that are ready to test label Apr 8, 2022
@codecov
Copy link

codecov bot commented Apr 8, 2022

Codecov Report

Merging #11057 (ad12bcc) into 5.x (ad04ee5) will increase coverage by 0.15%.
The diff coverage is 50.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                5.x   #11057      +/-   ##
============================================
+ Coverage     48.99%   49.15%   +0.15%     
  Complexity    35399    35399              
============================================
  Files          2147     2147              
  Lines        105609   105637      +28     
============================================
+ Hits          51744    51921     +177     
+ Misses        53865    53716     -149     
Impacted Files Coverage Δ
...undle/Security/Firewall/AuthenticationListener.php 53.52% <50.00%> (ø)
...p/bundles/InstallBundle/Command/InstallCommand.php 68.52% <0.00%> (-2.76%) ⬇️
...ndles/FormBundle/EventListener/PointSubscriber.php 100.00% <0.00%> (ø)
...ndles/PageBundle/EventListener/PointSubscriber.php 100.00% <0.00%> (ø)
...undles/PageBundle/EventListener/PageSubscriber.php 73.07% <0.00%> (+0.34%) ⬆️
...undles/CoreBundle/EventListener/CoreSubscriber.php 82.55% <0.00%> (+0.67%) ⬆️
...s/EmailBundle/EventListener/CampaignSubscriber.php 65.76% <0.00%> (+0.95%) ⬆️
...es/FormBundle/EventListener/CampaignSubscriber.php 77.27% <0.00%> (+1.66%) ⬆️
...es/PageBundle/EventListener/CampaignSubscriber.php 23.65% <0.00%> (+1.67%) ⬆️
...dles/EmailBundle/EventListener/PointSubscriber.php 80.95% <0.00%> (+2.00%) ⬆️
... and 15 more

RCheesley
RCheesley previously approved these changes May 27, 2022
Copy link
Sponsor Member

@RCheesley RCheesley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with the regular user login but unfortunately between the instructions in the linked PR and the developer docs I was not able to fathom how to test the OAuth2 login or SSO. So someone will need to check both of those (and we should improve our docs on this!)

Copy link
Contributor

@biozshock biozshock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Form login and the oAuth2 worked as expected.

POST https://mautic.mautic/oauth/v2/token
Accept: application/json
Content-Type: application/json

{ "grant_type": "client_credentials", "client_id": "<redacted>", "client_secret": "<redacted>" }
HTTP/1.1 200 OK
...
{
  "access_token": "ODdmNzk2ODBmYTlkM2YzMzViZDQxNjI4ZDNmYTQ0YjRmNmZlOTNkZDI5MjYyMzA4MzhlZjQwMWRlZTM3NjAxNg",
  "expires_in": 3600,
  "token_type": "bearer",
  "scope": null
}
GET https://mautic.mautic/api/contacts
Accept: application/json
Authorization: Bearer ODdmNzk2ODBmYTlkM2YzMzViZDQxNjI4ZDNmYTQ0YjRmNmZlOTNkZDI5MjYyMzA4MzhlZjQwMWRlZTM3NjAxNg
HTTP/1.1 200 OK
...
{
  "total": "14",
  "contacts": {
    "29": {
      "isPublished": true,
.....

@escopecz escopecz added ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged and removed ready-to-test PR's that are ready to test labels Sep 9, 2022
@escopecz escopecz merged commit 28188c3 into mautic:5.x Sep 9, 2022
@escopecz escopecz deleted the TPROD-296 branch September 9, 2022 07:32
escopecz added a commit to escopecz/mautic that referenced this pull request Sep 13, 2022
* Disabling the cookie service mocking for tests as it causes problems

We'll see what this breaks

* Functional tests for Oauth2

* The lazy anonymous mode prevents the session from being started if there is no need for authorization

New feature of Symfony 4.4

* Removing deprecated interface from AuthenticationListener

* Adding option to skip setting mock services in a test

* Fixing test that was not asserting anyting useful

* CS fixes

* Fixing the flag condition

* Backing up the strict type for providerKey as it seems it can come in different shapes

* Making the class final and properties for AuthenticationListener private as there is no need for extending it

* CS fix

* Fixing several tests that were missing the table prefix

* Trying to revert the change in Abstract test case to see if that's why so many tests are failing

* CS fix

* Oops, I meant to leave this line uncommented

* CS fix

* Trying if the lazy value is breaking the tests

* Trying to run the new test in a new process

* Yes! New process worked. Adding back what was removed to find out what's breaking the tests

* Improving tests to print the response for debugging

* Adding response content to the asssertion checks for debugging

* Documenting the BC break about AuthenticationListener

* Trying without enableReboot

* Finally figured out why it was trying to install Mautic. It was missing mail from config
@escopecz escopecz added the bug Issues or PR's relating to bugs label Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bc-break A BC break PR for major release milestones only bug Issues or PR's relating to bugs cla-signed The PR contributors have signed the contributors agreement ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants