Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add cookie strategy configuration to PHP request handler #1753
base: trunk
Are you sure you want to change the base?
Add cookie strategy configuration to PHP request handler #1753
Changes from 6 commits
e6ee1b7
934d1be
f77d0c5
e532d08
4938594
985fe83
ef8e39e
364e7de
3ab3876
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I'm starting to think we should just ship a WordPress plugin to log the user in the first time they interact with the site. It could go like this:
login
step would install that mu-plugin. Or maybe the plugin would always be there andlogin
would just set some constant to activate it?wordpress_user_was_auto_logged
. If it's present, we're done. If it's missing, set it and also log the user in.This should work in all runtimes (Studio, Playground CLI, WP-NOW, Playground webapp) without any runtime-specific loginc.
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.
Claude gave me this. Coming from AI, there's likely some problem with that code, but it seems like a good starting point:
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.
Yeah, good idea. However, I'm concerned about using a plugin in Studio's case, since we'd need to filter it out when exporting the site.
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.
Oh I don't want to pollute the exports, filtering files out just doesn't work as a long term strategy. The login plugin would live in
/internal/shared/mu-plugins
with the rest of the platform-level mu-plugins to keep the site clean.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.
Ah, ok, I didn't know about this approach 😅.
Still, I wonder about how we could make this plugin work so the user can decide when it should auto-login and when not. If I understand correctly the code shared here, the
init
hook will make that all requests are logged, right?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.
@fluiddot here's my thinking:
AUTOLOGIN_USERNAME
is present.autologin_performed
autologin_performed
cookie is already set, no autologin happens.This way the user will remain logged in until they explicitly log out, at which point they'll remain logged out until they explicitly log in. A private browsing session will still default to the logged in state.
There could also be a "querystring mode" where autologin is only performed when
$_GET['playground-autologin']
is present. This would give Studio a link-based control while still allowing the Playground webapp and CLI to default to autologin.What do you think?
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.
The approach looks good to me, thanks @adamziel ! I'll try to work on this in the next few days. Note that the original issue lowered its priority, so I might delay updating the PR.
At least for the Studio app, and probably when using node clients, this will be necessary to ensure that API requests to the site are not auto-logged. This is important when using, for instance, API keys as referenced in Automattic/studio#387.
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.
A check like
if(!$ajax && !$rest_api)
could also help solve for the API requests. Anyway, whatever's most useful here.