activitypub icon indicating copy to clipboard operation
activitypub copied to clipboard

WordPress compatibility

Open pfefferle opened this issue 3 years ago • 8 comments

Hey @landrok , I am the author of the WordPress ActivityPub Plugin (https://github.com/pfefferle/wordpress-activitypub) and @mediaformat and I investigated if it is possible to use your lib in the plugin, so I have some questions.

  • WordPress comes with it's own API endpoints and with it's request handlers, do you see a way to provide a bit more generic way to verify requests, withouth the requirement of guzzle or symfony?
  • Because we can't use the server part of your lib, what do you think about a fromJson method for the Activity Objects, so that we will be able to init the objects, using the JSON request?

pfefferle avatar Jan 29 '21 20:01 pfefferle

Hey @pfefferle, nice to hear you.

HTTP Client

I don't have a lot of experiences on Wordpress but as far as I know, Wordpress has its own HTTP "stack" such as functions like wp_get_http(), wp_post_http() etc... and static shortcut methods in the WP_Http class like WP_Http::get(), WP_Http::get() etc...

Do you know if there are some higher level methods that implements PSR 7 / ? The idea behind this is to implement a driver parameter, as it has been made for caching or logging, so that you may configure it on the fly.

fromJson

I just released a version 0.5.5 with a fromJson() method.

Server part

The server part of this library does not listen on any port. It's more intended to be integrated in a controller method. It's a precision because I don't know if this is the blocking aspect in your usage.

landrok avatar Jan 31 '21 18:01 landrok

Hey @landrok, sorry for the late reply.

I just released a version 0.5.5 with a fromJson() method.

Nice, thanks!

HTTP Client

As you said, WordPress has it's own WP_Http class and mainly uses https://github.com/WordPress/Requests and there is sadly no PSR-7 planned any time soon: https://github.com/WordPress/Requests/issues/320

Nevertheless, do you see a way to remove the hard dependencies of the guzzlehttp/guzzle, symfony/http-foundation, symfony/cache and monolog/monolog? Maybe to only use the PSR interfaces, so that we will be able to implement them mapping the internal handlers/classes.

Alternative

If this is not possible (at least in short term), do you think it make sense to "only" use the Activity Objects and keep the server handling we currently use?

pfefferle avatar Feb 05 '21 15:02 pfefferle

Hey @landrok

how likely is it, that the PSR 7 driver feature will make it into the code?

Do you know if there are some higher level methods that implements PSR 7 / ? The idea behind this is to implement a driver parameter, as it has been made for caching or logging, so that you may configure it on the fly.

Are you willing to accept pull requests?

pfefferle avatar May 09 '22 18:05 pfefferle

Hey Matthias, First, sorry for the long time since your previous issues. I have played a little bit with WP HTTP features, implemented some anonymous functions to switch between "HTTP driver" (default implementation could be overridden by these anonymous features). I have not published anything because I was not satisfied. Finally I decided to take some time to think about it. And I think you know the following... So, I am still interested in an implementation of PSR 7 as a driver feature but I have not enough time these days to implement it. Of course, I will accept pull requests with pleasure and I would take the time to review them.

landrok avatar May 09 '22 20:05 landrok

I have two more questions if you don't mind:

  • why does the lib use "guzzle" and "HttpFoundation"? Do you think it is possible to only use a PSR compatible request handler, so I can try to mock it for WordPress?
  • are you fine with making the signature verification configurable, so that I can try to use an alternative to phpseclib?

pfefferle avatar May 11 '22 06:05 pfefferle

Guzzle and HTTP foundation

Guzzle is used as an HTTP client and should be replaced by PSR-18 (ie: https://github.com/landrok/activitypub/blob/master/src/ActivityPhp/Server/Http/Request.php#L42)

HTTP foundation is used as HTTP message and should be replaced by PSR-7 (ie: https://github.com/landrok/activitypub/blob/master/src/ActivityPhp/Server/Http/HttpSignature.php#L66)

Maybe the 2 should be handled as 2 distinct commits, don't you think ?

Signature verification

It could be great. It goes beyond the scope of this "Wordpress compatibility" issue and needs another one that let us discuss about alternatives before implementing.

landrok avatar May 11 '22 08:05 landrok

By the way @Art4 has an open PR to Add PSR-7 support, with an accompanying PSR18-Adapter if anyone is able to test it with this library!

mediaformat avatar Oct 30 '22 04:10 mediaformat

Thanks for mentioning me :+1: Atm the adapter is only supporting Requests v2, but I'm working at support for Requests v1 too.

I would be glad if my library could be helpful.

Update: I released 1.0.0 with support for Requests v1 and v2.

Art4 avatar Oct 31 '22 18:10 Art4