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

logmeinUrl package and usage #52909

Closed
wants to merge 6 commits into from
Closed

logmeinUrl package and usage #52909

wants to merge 6 commits into from

Conversation

lsl
Copy link
Contributor

@lsl lsl commented May 17, 2021

Changes proposed in this Pull Request

  • Add logmeingUrl method to append the logmein parameter defined in D61461-code

Testing instructions

  • Apply D61461-code (dependency, since deployed)
  • Login to http://calypso.localhost:3000/, create a private site with a mapped domain (or log into my test user for testing23465324891.home.blog/)
  • oauth flag set for testing without 3pc, and logmein flag set for testing this feature, e.g. visit http://calypso.localhost:3000/?flags=oauth,logmein
  • Click here: image

You should end up the site in a logged in state with cookies against the mapped domain.

  • Test both while logged out of the test site directly.
  • Test sub.subdomain.blog domains include the param
  • Test mapped.com domains include the param
  • Test wpcomstaging urls do not include the param
  • Test domain redirects do not include the param
  • Test Atomic sites do not include the param

For testing in calypso using chrome with third party cookies disabled you'll need to use calypso's oauth mode, e.g. http://calypso.localhost:3000/domains/manage/testing23465324891.home.blog?flags=oauth,logmein.

Unit tests:

yarn test-client client/lib/logmein

Related to #52741 / #52740 / #52763

@lsl lsl self-assigned this May 17, 2021
@lsl lsl added the [Feature] 3rd Party Cookies Management Handling third-party cookies (or the lack thereof) on WordPress.com. label May 17, 2021
@github-actions
Copy link

Test live: https://calypso.live/?branch=add/logmein

@aneeshd16
Copy link
Contributor

Adding a link on the domain management page would also work!
image

@matticbot
Copy link
Contributor

matticbot commented May 18, 2021

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~304 bytes added 📈 [gzipped])

name     parsed_size           gzip_size
domains       +667 B  (+0.1%)     +304 B  (+0.1%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

return fullUrl;
}

url.searchParams.set( 'logmein', '1' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of appending logmein param, would it make sense to directly take a logged in user to the the r-login.wordpress.com endpoint? If the user is in Calypso and logged in, we don't need to take them to wordpress.com/log-in - we can take them to https://r-login.wordpress.com/remote-login.php?action=link&back=https://{MAPPED_DOMAIN.tld} and save the extra log in screen step:

Screenshot_2021-05-21_at_2_34_34_AM

Appending logmein=1 is okay if we find the user is logged out for some reason. So, I'm thinking:

if ( isLoggedIn ) {
  navigate to https://r-login.wordpress.com/remote-login.php?action=link&back=https://{MAPPED_DOMAIN.tld}
} else {
  navigate to https://mapped-domain.tld/?logmein=1
}

A scenario in which this may not work is if the user has Calypso open in a tab, logs out of WPCOM in a different tab, and clicks on "Visit site" button on the open Calypso tab. Then they'll still be logged in to the mapped domain even though they're not signed in to WPCOM. Probably there are some checks we can add to handle this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be fine, I'll see what I can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this here: https://github.com/Automattic/wp-calypso/pull/52909/files#diff-d025c6a21229fe69836222916356ee8a2c395861252a82ff88e97b9facc70a4bR31

But it didn't seem to work for some reason (didn't dig too deep) end up getting js output as plaintext directly from `remote-login.php

Copy link
Contributor

@niranjan-uma-shankar niranjan-uma-shankar left a comment

Choose a reason for hiding this comment

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

Should we also add these logmein links to the editor?

Screenshot 2021-05-21 at 1 54 46 PM

Screenshot 2021-05-21 at 1 55 00 PM

A couple of other places:

In themes page after activating a theme:

Screenshot 2021-05-21 at 1 59 13 PM

In the Reader where the title links to the mapped domain site:

Screenshot 2021-05-21 at 2 00 40 PM

@lsl
Copy link
Contributor Author

lsl commented May 26, 2021

Reworked this as a client lib for simplicity and updated code to match up with what @JoshuaGoode is dropping in the demo. Depends on the latest update in D61461-code.

Edit: Just noticed I nuked the tests in the process, will add them back tomorrow and amend to include the new selector. (Maybe, if we're still going this way)


// return (
// 'https://r-login.wordpress.com/remote-login.php?action=link&back=' +
// encodeURIComponent( fullUrl )
Copy link
Contributor

Choose a reason for hiding this comment

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

This should work, since I have a similar implementation in #53125 and it works well. One thing to note is that the back URL should be https instead of http. When I tested this PR by clicking on the mapped domain link on the domain management page, I was taken to the following URL which outputted JS on the screen:

https://r-login.wordpress.com/remote-login.php?action=link&back=http%3A%2F%2Fniranjan792177516.blog

Note the http in the back URL. When I changed that https, then the r-login redirect worked well.

Anyhow, with the change in D61461-code to skip the Continue step, is this change still needed?

@@ -398,7 +400,7 @@ export class List extends React.Component {
<div className="list__header-primary-domain-content">
<ExternalLink
className="list__header-primary-domain-url"
href={ selectedSite.URL }
href={ logmeinUrl( selectedSite.URL, siteUrls ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you like to include in this PR the logmeinUrl()'ification of other instances in Calypso that link to the mapped domain URL? We might have to do this in the editor, reader and so on. Or do you think we should take that as a separate PR?

: false
)
.filter( Boolean );
return result;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if this is the correct list of restrictions.. do we have an "is simple site" method by chance?

Copy link
Contributor

@niranjan-uma-shankar niranjan-uma-shankar Jun 7, 2021

Choose a reason for hiding this comment

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

I don't know the right answer to this, but here's what I found.
We have this selector that returns true if a site is a WPCOM site(atomic or simple) as described the JS Doc:

Whether the site is a WPCOM site ( Atomic or Simple )

Using the logic in that selector, the following should return simple sites:

! isJetpackSite( state, siteId ) || ! isAtomicSite( state, siteId )

Would this be the right check for WPCOM simple sites?

@lsl
Copy link
Contributor Author

lsl commented Jun 8, 2021

Moving focus to replacement: #53443

@lsl lsl closed this Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] 3rd Party Cookies Management Handling third-party cookies (or the lack thereof) on WordPress.com.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants