Automattic / wordpress-activitypub

ActivityPub for WordPress
https://wordpress.org/plugins/activitypub/
MIT License
481 stars 72 forks source link

Blog in a subpath / webfinger test fails #37

Closed lapineige closed 5 years ago

lapineige commented 5 years ago

My wordpress is installed in domain.tld/subpath. When I try to test the webfinger part, it fails. With both username@domain.tld ("invalid content-type: text/html") and username@domain.tld/subdomain (<- this one gives me an encoding error "invalid URL escape "%2F"").

Is this plugin compatible with subpath ?

pfefferle commented 5 years ago

WebFinger does not support subdirectories, so you have to create a .htaccess file in your root and forward the request to your blog directory.

lapineige commented 5 years ago

And for Nginx ? What rule should I use ?

celesteh commented 5 years ago

WebFinger does not support subdirectories, so you have to create a .htaccess file in your root and forward the request to your blog directory.

This is the .htaccess file that worked for me. "blog" is the name of the subdirectory. You would need to use your own instead:

RedirectMatch "^\/\.well-known(.*)$" "\/blog\/\.well-known$1"

It would be super if this could be documented somewhere within the plugin, such as the faq

lapineige commented 5 years ago

How can I use that rule with Nginx ?

lapineige commented 5 years ago

I tried with rewrite ^/.well-known/ ^/subdirectory/.well-known/ last;. It doesn't work. I have this error (using https://client.webfinger.net/lookup) invalid content-type: text/html. And it tries to connect to : https://domain.tld/.well-known/webfinger?resource=acct%3Ablog%40domain.tld

lapineige commented 5 years ago

I'm wondering : I tried to do that change in nginx config file for my wordpress, not for the root domain. But I need to change the root domain, right ? So when webfinger tries to access domain.tld/.well_known, it redirects to domain.tld/blog/.well_known ?

pfefferle commented 5 years ago

exactly!

lapineige commented 5 years ago

He doesn't work, same error, text/html content :(

lapineige commented 5 years ago

Ok I fixed this problem: I was due to Yunohost SSO, which were blocking any public access to this file.

Now the redirection is working.

Here is the solution:

location /.well-known/ {
        return 301 https://$server_name/YourSubFolder/$request_uri;
}

https://client.webfinger.net shows the json.

But I still can't see my blog from Mastodon.

pfefferle commented 5 years ago

Can you give me your identifier?

lapineige commented 5 years ago

Search for [removed]

pfefferle commented 5 years ago

Two things:

lapineige commented 5 years ago

You are redirecting your profile URLs https://lapineige.fr/wp/blog/author/lapineige/ to the main URL, but they are required for ActivityPub! Perhaps you use YoastSEO?

Uh… that's not on purpose… No I don't use this plugin.

I am not sure if mastodon supports http redirects

It works for Nextcloud.

pfefferle commented 5 years ago

But what/who is redirecting your profile pages?

lapineige commented 5 years ago

I don't know…

lapineige commented 5 years ago

Ok I found the plugin (NinjaFirewall) that was changing the default behaviour.

But now the WebFinger tool gives me a 403 forbidden (as before my rewrite). But if I try to connect to the URL it tries to reach, the redirection is working…

pfefferle commented 5 years ago

Can you try to refresh the permalinks of your blog? go to the permalinks page and simply press the save button... you do not have to change anything...

lapineige commented 5 years ago

Done, same result.

lapineige commented 5 years ago

So here is the current status: the redirect works on the browser. With curl, it shows a 301. With curl -L it follows the redirect and I have a 403.

lapineige commented 5 years ago

Ok, in fact a wordpress upgrade changed my nginx config (I use it with Yunohost). I fixed that. It works :slightly_smiling_face: - even if I can't see the blog posts (the number is correct on the profile) but I guess it needs time to federate.

Problem solved, thanks a lot :tada:

celesteh commented 5 years ago

Hi, I appreciate that you don't want to keep issues open when the solution is known, but has this actually been documented any place else but in these issues?

I'd do a pull request, but it doesn't seem like the README is the best location and other help files are not immediately obvious.

lapineige commented 5 years ago

Well I didn't want to spam again @pfefferle with my problems ^^

I don't know where to put this, I'm actually writing a blog post (in French) to talk about this plugin, but my problem was kind of specific and I don't know if it's a good idea to explain the solutions in a place where it's hard to find, while here in the issues it's kind of easier to found it.

pfefferle commented 5 years ago

If you can also write an English version I can add it to the faq section of the readme...

lapineige commented 5 years ago

That's an idea… I will see if I have some time to do it, then I'll give you the link :)

lapineige commented 4 years ago

After sometimes, I discovered that my nginx config changed, and I'm not sure I kept the previous one.

I tried to reconfigure it, with

location /.well-known/ {
        return 301 https://$server_name/subfolder/$request_uri;
}

But it doesn't work from Mastodon and https://webfinger.net/lookup/ gives me this:

Error getting JRD: 400 Bad Request

A curl https://domain.tld/.well-known gives a 301 Moved Permanently, which is normal (it should redirect to https://domain.tld/subfolder/.well-known). But a curl -L https://domain.tld/.well-known/ gives a 404, a curl -L https://domain.tld/.well-known/webfinger a :

{"code":"rest_missing_callback_param","message":"Missing parameter: resource","data":{"status":400,"params":["resource"]}

And curl -L https://domain.tld/subfolder/blog/author/pseudo/ a :

{"code":"activitypub_unsupported_resource","message":"Resource is invalid","data":{"status":400}}

I'm lost, I don't remember which URL I should test, and how to configure Nginx…

pfefferle commented 4 years ago

The URL you have to check is https://domain.tld/.well-known/webfinger?resource=acct:username@domain.tld

pfefferle commented 4 years ago

{"code":"rest_missing_callback_param","message":"Missing parameter: resource","data":{"status":400,"params":["resource"]}

This error is correct! It says, that your rewrite seems to work, but you pass no resource param.

pfefferle commented 4 years ago

Here a working example: https://notiz.blog/.well-known/webfinger?resource=acct:pfefferle@notiz.blog

lapineige commented 4 years ago

https://webfinger.net/lookup/?resource=https%3A%2F%2Fnotiz.blog%2F.well-known%2Fwebfinger%3Fresource%3Dacct%3Apfefferle%40notiz.blog 404 not found 😅

edit: curl gives the right result

lapineige commented 4 years ago

For my domain, I have a 400 bad request and {"code":"activitypub_unsupported_resource","message":"Resource is invalid","data":{"status":400}}

lapineige commented 4 years ago

If I try with an article from my wordpress (the last one, that doesn't appear on mastodon): 422 Validation failed : text can't be blank

lapineige commented 4 years ago

Ok now instead of using https://$server_name/YourSubFolder/$request_uri; (https://github.com/YunoHost-Apps/wordpress_ynh/issues/61#issuecomment-490521823) I replaced $server_name with the actual domain.tld, and now https://domain.tld/.well-known/webfinger?resource=acct:username@domain.tld works. But I can't see my article on mastodon.

pfefferle commented 4 years ago

Can you post some real URLs, so I can check them?

pfefferle commented 4 years ago

Is it the URL from your GitHub profile? If so, it does return the JSON response but without content.

Request:

curl "https://lapineige.fr/wp/blog/2020/04/retour-dexperience-sur-le-format-dimage-webp-un-excellent-rapport-qualite-poids/" \
     -H 'Accept: application/activity+json'

Response:

{
  "@context": [
    "https:\/\/www.w3.org\/ns\/activitystreams",
    "https:\/\/w3id.org\/security\/v1",
    {
      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
      "PropertyValue": "schema:PropertyValue",
      "schema": "http:\/\/schema.org#",
      "value": "schema:value"
    }
  ],
  "id": "https:\/\/lapineige.fr\/wp\/blog\/2020\/04\/retour-dexperience-sur-le-format-dimage-webp-un-excellent-rapport-qualite-poids\/",
  "type": "Note",
  "published": "2020-04-28T16:15:58Z",
  "attributedTo": "https:\/\/lapineige.fr\/wp\/blog\/author\/lapineige\/",
  "summary": null,
  "inReplyTo": null,
  "content": null,
  "contentMap": {
    "fr": null
  },
  "to": [
    "https:\/\/www.w3.org\/ns\/activitystreams#Public"
  ],
  "cc": [
    "https:\/\/www.w3.org\/ns\/activitystreams#Public"
  ],
  "attachment": [],
  "tag": []
}

Do you use a pagebuilder or a multi language plugin?

lapineige commented 4 years ago

Thank you. I don't think I use any pagebuilder, and I don't use a multi-language plugin… It was working a few months ago, I didn't test it in the mid-time…

pfefferle commented 4 years ago

Hmmm... I just tested it with my site and it seems to work properly:

curl "https://notiz.blog/2020/03/15/i-am-a-human-of-wordpress/" \
     -H 'Accept: application/activity+json'

Also when I search for the URL on mastodon.

lapineige commented 4 years ago

It works for me too from Mastodon.


EditorsKit and Stackable, that I used to add more blocks, are not in the pagebuilder category, right ?

lapineige commented 4 years ago

Ooooook that's super weird: I tried to change Activity-Object-Type (I changed a random parameter), saved it, then disabled an enabled again the extension, and while curl still fails, I can see it with the URL on Mastodon… And I have the tittle and a link, which is the format I always wanted… but couldn't have for some reason.

Thanks a lot for your help :)

pfefferle commented 4 years ago

:blush: