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

feat: Add support for Cookie configuration and logout mutation #129

Merged
merged 36 commits into from
Dec 27, 2024

Conversation

alexookah
Copy link
Contributor

@alexookah alexookah commented Aug 3, 2024

What

This PR enhances the loginCookie functionality by introducing a new AuthCookie class. This class adds options for configuring the cookie's expiration and SameSite attribute. This should resolve this issue.

Why

Currently, the authentication cookie being set is session-only. This means that when a user closes their browser, they need to re-authenticate upon reopening. This change allows for persistent authentication sessions, reducing the need for frequent logins.

How

This PR introduces the AuthCookie class which replaces the default behavior for setting authentication cookies. The AuthCookie class:

Provides the option to set a custom expiration time for the authentication cookie.
Supports the SameSite attribute for cookies, which enhances security by controlling how cookies are sent with cross-site requests.
Allows users to set the cookie as persistent if they opt for the "remember me" functionality, which is currently not supported by default.

Testing Instructions

Login using a Login provider. Verify cookies and check that SameSite is set to None.

Additional Info

Things to improve: Add options in admin for samesite configuration & domain cookie.

Checklist:

  • My code is tested to the best of my abilities.
  • My code follows the WordPress Coding Standards.
  • My code has proper inline documentation.
  • I have added unit tests to verify the code works as intended.
  • I included the relevant changes in CHANGELOG.md

@alexookah alexookah changed the title Add AuthCookie Add AuthCookie for Login with Cookie SameSite option Aug 3, 2024
@alexookah alexookah changed the title Add AuthCookie for Login with Cookie SameSite option Add AuthCookie for Login with SameSite Cookie Aug 3, 2024
@alexookah alexookah changed the title Add AuthCookie for Login with SameSite Cookie Add AuthCookie for Login with SameSite Cookie option Aug 3, 2024
@alexookah alexookah changed the title Add AuthCookie for Login with SameSite Cookie option Add AuthCookie for Login with SameSite cookie option Aug 3, 2024
Copy link
Member

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

Reviewing from my phone, but issue seems to be method name youre using.

(Feel free to ingore the other feedback if you want, happy to handle myself when I'm implementing docs/tests)

src/Auth/AuthCookie.php Outdated Show resolved Hide resolved
src/Auth/AuthCookie.php Outdated Show resolved Hide resolved
src/Auth/AuthCookie.php Outdated Show resolved Hide resolved
src/Auth/AuthCookie.php Outdated Show resolved Hide resolved
src/Auth/Auth.php Outdated Show resolved Hide resolved
@justlevine
Copy link
Member

@alexookah I've rebased this on the current develop branch to fix some issues with ci and testing in WP 6.6. Please make sure to pull --force before committing/pushing any additional changes to this PR.

@coveralls
Copy link

coveralls commented Aug 25, 2024

Coverage Status

coverage: 81.787% (-0.1%) from 81.924%
when pulling 1eed7c4 on alexookah:custom_wp_auth_cookie
into 72936f4 on AxeWP:develop.

@justlevine justlevine force-pushed the custom_wp_auth_cookie branch from 6565e17 to 2f302cb Compare September 7, 2024 11:59
src/Auth/AuthCookie.php Outdated Show resolved Hide resolved
@justlevine
Copy link
Member

I've begun implementing a more scalable UX that should provide a path forward on this in #141 .

So far, settings have been broken up into different screens, so we can scale horizontally instead of vertically:
image

Once I clean up the provider settings and conditional logic, we should be able to rebase this paying closer attention to what Login/ Cookie settings should be available on a provider level versus globally.

@justlevine justlevine mentioned this pull request Oct 20, 2024
14 tasks
@justlevine
Copy link
Member

Refactored cookie settings to their own group in 7024674

image

@alexookah
Copy link
Contributor Author

@justlevine New UI looks awesome!
Whats pending now?

@justlevine
Copy link
Member

Integration (WPUnit) tests are the big one. Everything else I believe can be handled iteratively after this is merged/released.

I also need to fix the setting value denouncing before triggering a release, but that's outside the scope of this PR.

@justlevine
Copy link
Member

Getting closer. Only things left to write tests for are the logout mutation and the mode/domain values.

Hope is to get this merged and a release trigged this week 🤞

@alexookah if you're free and don't mind testing the cookie generation locally, I'd be much appreciated. Only so much I can stub, and setcookies() tends to behave differently depending on the server environment.

@justlevine justlevine self-requested a review December 22, 2024 11:46
Copy link
Member

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

Code-wise looks good. needs manual testing of cookie generation/consumption before merge.

justlevine added a commit to justlevine/wp-graphql-headless-login that referenced this pull request Dec 22, 2024
Backported from AxeWP#129
@justlevine justlevine mentioned this pull request Dec 22, 2024
5 tasks
justlevine added a commit that referenced this pull request Dec 22, 2024
Backported from #129
@justlevine justlevine changed the title Add AuthCookie for Login with SameSite cookie option feat: Add support for Cookie configuration and logout mutation Dec 27, 2024
@justlevine justlevine merged commit 3cc4c74 into AxeWP:develop Dec 27, 2024
13 of 21 checks passed
@alexookah
Copy link
Contributor Author

Getting closer. Only things left to write tests for are the logout mutation and the mode/domain values.

Hope is to get this merged and a release trigged this week 🤞

@alexookah if you're free and don't mind testing the cookie generation locally, I'd be much appreciated. Only so much I can stub, and setcookies() tends to behave differently depending on the server environment.

Just tested it out with the released version of 4.0.
Everything works great!

Thank you very much @justlevine for improving everything in this PR.
Great work

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.

3 participants