finalize account handling
still missing: publishing
This commit is contained in:
parent
c02702f773
commit
75a77b3f5c
11 changed files with 39 additions and 15 deletions
|
@ -472,7 +472,6 @@ class Base_Object {
|
|||
public function get( $key ) {
|
||||
if ( ! $this->has( $key ) ) {
|
||||
return new WP_Error( 'invalid_key', 'Invalid key' );
|
||||
|
||||
}
|
||||
|
||||
return $this->$key;
|
||||
|
|
|
@ -71,16 +71,16 @@ class Activitypub {
|
|||
* @return string The new path to the JSON template.
|
||||
*/
|
||||
public static function render_json_template( $template ) {
|
||||
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
if ( ! is_activitypub_request() ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
$json_template = false;
|
||||
|
||||
if ( ! \is_author() && ! \is_singular() && ! \is_home() ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
// check if user can publish posts
|
||||
if ( \is_author() && ! User_Factory::get_by_id( \get_the_author_meta( 'ID' ) ) ) {
|
||||
return $template;
|
||||
|
|
|
@ -107,7 +107,7 @@ class Signature {
|
|||
*/
|
||||
public static function generate_signature( $user_id, $http_method, $url, $date, $digest = null ) {
|
||||
$user = User_Factory::get_by_id( $user_id );
|
||||
$key = $user->get_private_key();
|
||||
$key = $user->get__private_key();
|
||||
|
||||
$url_parts = \wp_parse_url( $url );
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ function is_activitypub_request() {
|
|||
* ActivityPub requests are currently only made for
|
||||
* author archives, singular posts, and the homepage.
|
||||
*/
|
||||
if ( ! \is_author() && ! \is_singular() && ! \is_home() && ! defined( 'REST_REQUEST' ) && ! REST_REQUEST ) {
|
||||
if ( ! \is_author() && ! \is_singular() && ! \is_home() && ! defined( '\REST_REQUEST' ) && ! \REST_REQUEST ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class Application_User extends Blog_User {
|
|||
return $this::get_name();
|
||||
}
|
||||
|
||||
public function get_public_key() {
|
||||
public function get__public_key() {
|
||||
$key = \get_option( 'activitypub_application_user_public_key' );
|
||||
|
||||
if ( $key ) {
|
||||
|
@ -58,7 +58,7 @@ class Application_User extends Blog_User {
|
|||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_private_key() {
|
||||
public function get__private_key() {
|
||||
$key = \get_option( 'activitypub_application_user_private_key' );
|
||||
|
||||
if ( $key ) {
|
||||
|
|
|
@ -150,7 +150,7 @@ class Blog_User extends User {
|
|||
return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
|
||||
}
|
||||
|
||||
public function get_public_key() {
|
||||
public function get__public_key() {
|
||||
$key = \get_option( 'activitypub_blog_user_public_key' );
|
||||
|
||||
if ( $key ) {
|
||||
|
@ -169,7 +169,7 @@ class Blog_User extends User {
|
|||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_private_key() {
|
||||
public function get__private_key() {
|
||||
$key = \get_option( 'activitypub_blog_user_private_key' );
|
||||
|
||||
if ( $key ) {
|
||||
|
@ -193,4 +193,8 @@ class Blog_User extends User {
|
|||
public function get_attachment() {
|
||||
return array();
|
||||
}
|
||||
|
||||
public function get_canonical_url() {
|
||||
return \home_url();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,19 @@ class User extends Actor {
|
|||
}
|
||||
|
||||
public function get_public_key() {
|
||||
return array(
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'publicKeyPem' => $this->get__public_key(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $this->get__id()
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get__public_key() {
|
||||
$key = \get_user_meta( $this->get__id(), 'magic_sig_public_key', true );
|
||||
|
||||
if ( $key ) {
|
||||
|
@ -139,7 +152,7 @@ class User extends Actor {
|
|||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_private_key() {
|
||||
public function get__private_key() {
|
||||
$key = \get_user_meta( $this->get__id(), 'magic_sig_private_key', true );
|
||||
|
||||
if ( $key ) {
|
||||
|
@ -242,4 +255,8 @@ class User extends Actor {
|
|||
public function get_resource() {
|
||||
return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
|
||||
}
|
||||
|
||||
public function get_canonical_url() {
|
||||
return $this->get_url();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,10 @@ class Users {
|
|||
*/
|
||||
\do_action( 'activitypub_outbox_pre' );
|
||||
|
||||
$user->set_context(
|
||||
\Activitypub\Model\Activity::CONTEXT
|
||||
);
|
||||
|
||||
$json = $user->to_array();
|
||||
|
||||
$response = new WP_REST_Response( $json, 200 );
|
||||
|
|
|
@ -55,7 +55,6 @@ class Webfinger {
|
|||
|
||||
$aliases = array(
|
||||
$user->get_url(),
|
||||
$user->get_canonical_url(),
|
||||
$user->get_at_url(),
|
||||
);
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
|
|||
|
||||
remove_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10 );
|
||||
}
|
||||
|
||||
public function test_dispatch_mentions() {
|
||||
$post = \wp_insert_post(
|
||||
array(
|
||||
|
|
|
@ -44,7 +44,7 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
|
|||
|
||||
$user = Activitypub\User_Factory::get_by_id( 1 );
|
||||
|
||||
$public_key = $user->get_public_key();
|
||||
$public_key = $user->get__public_key();
|
||||
|
||||
// signature_verification
|
||||
$verified = \openssl_verify( $signed_data, $signature_block['signature'], $public_key, 'rsa-sha256' ) > 0;
|
||||
|
@ -56,7 +56,7 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
|
|||
'pre_get_remote_metadata_by_actor',
|
||||
function( $json, $actor ) {
|
||||
$user = Activitypub\User_Factory::get_by_id( 1 );
|
||||
$public_key = $user->get_public_key();
|
||||
$public_key = $user->get__public_key();
|
||||
// return ActivityPub Profile with signature
|
||||
return array(
|
||||
'id' => $actor,
|
||||
|
|
Loading…
Reference in a new issue