Improve/webfinger (#616)

* Fix some WebFinger issues

* update changelog
This commit is contained in:
Matthias Pfefferle 2023-12-21 10:04:15 +01:00 committed by GitHub
parent a47c9cd7ae
commit 39c9288987
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 11 deletions

View file

@ -111,7 +111,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
* Fixed: Normalize attributes that can have mixed value types * Fixed: Normalize attributes that can have mixed value types
* Added: URL support for WebFinger * Added: URL support for WebFinger
* Added: Make Post-Template filterable * Added: Make Post-Template filterable
* Addes: CSS class for ActivityPub comments to allow custom designs * Added: CSS class for ActivityPub comments to allow custom designs
* Improved: WebFinger endpoints
### 1.3.0 ### ### 1.3.0 ###

View file

@ -38,6 +38,15 @@ class Application_User extends Blog_User {
return get_rest_url_by_path( 'application' ); return get_rest_url_by_path( 'application' );
} }
/**
* Returns the User-URL with @-Prefix for the username.
*
* @return string The User-URL with @-Prefix for the username.
*/
public function get_alternate_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
}
public function get_name() { public function get_name() {
return 'application'; return 'application';
} }

View file

@ -100,12 +100,12 @@ class Blog_User extends User {
} }
/** /**
* Returns the User-URL with @-Prefix for the username. * Get blog's homepage URL.
* *
* @return string The User-URL with @-Prefix for the username. * @return string The User-Url.
*/ */
public function get_at_url() { public function get_alternate_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); return \esc_url( \trailingslashit( get_home_url() ) );
} }
/** /**

View file

@ -135,8 +135,8 @@ class User extends Actor {
* *
* @return string The User-URL with @-Prefix for the username. * @return string The User-URL with @-Prefix for the username.
*/ */
public function get_at_url() { public function get_alternate_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() ); return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
} }
public function get_preferred_username() { public function get_preferred_username() {

View file

@ -94,10 +94,13 @@ class Webfinger {
$aliases = array( $aliases = array(
$user->get_url(), $user->get_url(),
$user->get_alternate_url(),
); );
$aliases = array_unique( $aliases );
$profile = array( $profile = array(
'subject' => $resource, 'subject' => sprintf( 'acct:%s', $user->get_resource() ),
'aliases' => array_values( array_unique( $aliases ) ), 'aliases' => array_values( array_unique( $aliases ) ),
'links' => array( 'links' => array(
array( array(

View file

@ -14,8 +14,8 @@ class Webfinger {
* Initialize the class, registering WordPress hooks * Initialize the class, registering WordPress hooks
*/ */
public static function init() { public static function init() {
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 ); \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 1, 3 );
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 ); \add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 1, 2 );
} }
/** /**
@ -34,6 +34,11 @@ class Webfinger {
return $array; return $array;
} }
$array['subject'] = sprintf( 'acct:%s', $user->get_resource() );
$array['aliases'][] = $user->get_url();
$array['aliases'][] = $user->get_alternate_url();
$array['links'][] = array( $array['links'][] = array(
'rel' => 'self', 'rel' => 'self',
'type' => 'application/activity+json', 'type' => 'application/activity+json',

View file

@ -111,7 +111,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
* Fixed: Normalize attributes that can have mixed value types * Fixed: Normalize attributes that can have mixed value types
* Added: URL support for WebFinger * Added: URL support for WebFinger
* Added: Make Post-Template filterable * Added: Make Post-Template filterable
* Addes: CSS class for ActivityPub comments to allow custom designs * Added: CSS class for ActivityPub comments to allow custom designs
* Improved: WebFinger endpoints
= 1.3.0 = = 1.3.0 =