From 38d77dec4b3f1f9439c9ad692b5a2a38e394f850 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sat, 24 Aug 2024 04:29:17 +0000 Subject: [PATCH 1/5] Remove discovery on each load if the client is is already cached. Start storing last modified date so we can refresh cache in future. --- ...class-indieauth-authorization-endpoint.php | 2 +- includes/class-indieauth-client-taxonomy.php | 42 +++++++++++-------- includes/class-indieauth-token-endpoint.php | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/includes/class-indieauth-authorization-endpoint.php b/includes/class-indieauth-authorization-endpoint.php index c3c221d..ff637ac 100644 --- a/includes/class-indieauth-authorization-endpoint.php +++ b/includes/class-indieauth-authorization-endpoint.php @@ -425,7 +425,7 @@ public function authorize() { $current_user = wp_get_current_user(); // phpcs:disable $client_id = esc_url_raw( wp_unslash( $_GET['client_id'] ) ); // WPCS: CSRF OK - $client_term = IndieAuth_Client_Taxonomy::add_client_with_discovery( $client_id ); + $client_term = IndieAuth_Client_Taxonomy::add_client( $client_id ); if ( ! is_wp_error( $client_term ) ) { $client_name = $client_term['name']; $client_icon = $client_term['icon']; diff --git a/includes/class-indieauth-client-taxonomy.php b/includes/class-indieauth-client-taxonomy.php index ba88876..affe29e 100755 --- a/includes/class-indieauth-client-taxonomy.php +++ b/includes/class-indieauth-client-taxonomy.php @@ -53,9 +53,9 @@ public static function register() { 'public' => true, 'publicly_queryable' => true, 'hierarchical' => false, - 'show_ui' => false, + 'show_ui' => true, 'show_in_menu' => false, - 'show_in_nav_menus' => true, + 'show_in_nav_menus' => false, 'show_in_rest' => false, 'show_tagcloud' => false, 'show_in_quick_edit' => false, @@ -79,14 +79,17 @@ public static function register() { 'show_in_rest' => true, ) ); - } - - /** - * Add Client from Discovery - */ - public static function add_client_with_discovery( $url ) { - $client = new IndieAuth_Client_Discovery( $url ); - return self::add_client( $url, $client->get_name(), $client->get_icon() ); + register_meta( + 'term', + 'last_modified', + array( + 'object_subtype' => 'indieauth_client', + 'type' => 'integer', + 'description' => __( 'Last Modified Client Timestamp', 'indieauth' ), + 'single' => true, + 'show_in_rest' => true, + ) + ); } /** @@ -157,6 +160,7 @@ public static function add_client( $url, $name = null, $icon = null ) { return $term; } add_term_meta( $term['term_id'], 'icon', $icon ); + add_term_meta( $term['term_id'], 'last_modified', time() ); return array_filter( array( 'url' => $url, @@ -182,10 +186,11 @@ public static function get_client( $url = null ) { $clients = array(); foreach ( $terms as $term ) { $clients[] = array( - 'url' => $term->description, - 'name' => $term->name, - 'id' => $term->term_id, - 'icon' => get_term_meta( $term->term_id, 'icon', true ), + 'url' => $term->description, + 'name' => $term->name, + 'id' => $term->term_id, + 'icon' => get_term_meta( $term->term_id, 'icon', true ), + 'last_modified' => get_term_meta( $term->term_id, 'last_modified', true ), ); } return $clients; @@ -214,10 +219,11 @@ public static function get_client( $url = null ) { $term = $terms[0]; return array( - 'url' => $term->description, - 'name' => $term->name, - 'id' => $term->term_id, - 'icon' => get_term_meta( $term->term_id, 'icon', true ), + 'url' => $term->description, + 'name' => $term->name, + 'id' => $term->term_id, + 'icon' => get_term_meta( $term->term_id, 'icon', true ), + 'last_modified' => get_term_meta( $term->term_id, 'last_modified', true ), ); } diff --git a/includes/class-indieauth-token-endpoint.php b/includes/class-indieauth-token-endpoint.php index 0592bb3..283d564 100644 --- a/includes/class-indieauth-token-endpoint.php +++ b/includes/class-indieauth-token-endpoint.php @@ -258,7 +258,7 @@ public function generate_token_response( $response ) { // Issue a token if ( ! empty( $scopes ) ) { - $client = IndieAuth_Client_Taxonomy::add_client_with_discovery( $response['client_id'] ); + $client = IndieAuth_Client_Taxonomy::add_client( $response['client_id'] ); if ( is_wp_error( $client ) ) { $client = array( 'id' => $client->get_error_message() ); } From fe7bd680e2b03b3ef2de61cb6c57b78cef06bb09 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 25 Aug 2024 17:36:15 +0000 Subject: [PATCH 2/5] Fix issue with infinite loop on new applications. --- includes/class-indieauth-client-discovery.php | 14 ++++---------- includes/class-indieauth-client-taxonomy.php | 6 +++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/includes/class-indieauth-client-discovery.php b/includes/class-indieauth-client-discovery.php index 43568e3..8f29c23 100644 --- a/includes/class-indieauth-client-discovery.php +++ b/includes/class-indieauth-client-discovery.php @@ -32,8 +32,9 @@ public function __construct( $client_id ) { if ( 'localhost' === wp_parse_url( $client_id, PHP_URL_HOST ) ) { return; } - + error_log( 'Pre-Parse' ); $response = self::parse( $client_id ); + error_log( 'Post-Parse' ); if ( is_wp_error( $response ) ) { error_log( __( 'Failed to Retrieve IndieAuth Client Details ', 'indieauth' ) . wp_json_encode( $response ) ); // phpcs:ignore return; @@ -113,15 +114,8 @@ private function parse( $url ) { $this->client_uri = $this->json['client_uri']; } } elseif ( 'text/html' === $content_type ) { - $content = wp_remote_retrieve_body( $response ); - $domdocument = new DOMDocument(); - libxml_use_internal_errors( true ); - if ( function_exists( 'mb_convert_encoding' ) ) { - $content = mb_convert_encoding( $content, 'HTML-ENTITIES', mb_detect_encoding( $content ) ); - } - $domdocument->loadHTML( $content ); - libxml_use_internal_errors( false ); - $this->get_mf2( $domdocument, $url ); + $content = wp_remote_retrieve_body( $response ); + $this->get_mf2( $content, $url ); if ( ! empty( $this->mf2 ) ) { if ( array_key_exists( 'name', $this->mf2 ) ) { $this->client_name = $this->mf2['name'][0]; diff --git a/includes/class-indieauth-client-taxonomy.php b/includes/class-indieauth-client-taxonomy.php index affe29e..4c5d9ed 100755 --- a/includes/class-indieauth-client-taxonomy.php +++ b/includes/class-indieauth-client-taxonomy.php @@ -143,7 +143,11 @@ public static function add_client( $url, $name = null, $icon = null ) { 'client_id' => $url, ); } - return self::add_client( $url, $client->get_name(), $client->get_icon() ); + $name = $client->get_name(); + $icon = $client->get_icon(); + if ( empty( $name ) ) { + $name = self::generate_slug( $url ); + } } $icon = self::sideload_icon( $icon, $url ); From 9d00bc56a9cba1ea1bdd796eecd381df0904f102 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 25 Aug 2024 20:26:27 +0000 Subject: [PATCH 3/5] Store client_uri in client term --- includes/class-indieauth-client-discovery.php | 4 +++ includes/class-indieauth-client-taxonomy.php | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/includes/class-indieauth-client-discovery.php b/includes/class-indieauth-client-discovery.php index 8f29c23..b9974bb 100644 --- a/includes/class-indieauth-client-discovery.php +++ b/includes/class-indieauth-client-discovery.php @@ -186,6 +186,10 @@ public function get_name() { return $this->client_name; } + public function get_uri() { + return $this->client_uri; + } + // Separate function for possible improved size picking later private function determine_icon( $input ) { if ( ! is_array( $input ) || empty( $input ) ) { diff --git a/includes/class-indieauth-client-taxonomy.php b/includes/class-indieauth-client-taxonomy.php index 4c5d9ed..bdda6e5 100755 --- a/includes/class-indieauth-client-taxonomy.php +++ b/includes/class-indieauth-client-taxonomy.php @@ -79,6 +79,18 @@ public static function register() { 'show_in_rest' => true, ) ); + register_meta( + 'term', + 'client_uri', + array( + 'object_subtype' => 'indieauth_client', + 'type' => 'string', + 'description' => __( 'IndieAuth Client Application URI', 'indieauth' ), + 'single' => true, + 'sanitize_callback' => 'esc_url_raw', + 'show_in_rest' => true, + ) + ); register_meta( 'term', 'last_modified', @@ -136,6 +148,8 @@ public static function add_client( $url, $name = null, $icon = null ) { return $exists; } + $client_uri = ''; + if ( empty( $name ) ) { $client = new IndieAuth_Client_Discovery( $url ); if ( defined( 'INDIEAUTH_UNIT_TESTS' ) ) { @@ -143,8 +157,9 @@ public static function add_client( $url, $name = null, $icon = null ) { 'client_id' => $url, ); } - $name = $client->get_name(); - $icon = $client->get_icon(); + $name = $client->get_name(); + $icon = $client->get_icon(); + $client_uri = $client->get_uri(); if ( empty( $name ) ) { $name = self::generate_slug( $url ); } @@ -163,7 +178,13 @@ public static function add_client( $url, $name = null, $icon = null ) { if ( is_wp_error( $term ) ) { return $term; } - add_term_meta( $term['term_id'], 'icon', $icon ); + if ( ! empty( $icon ) ) { + add_term_meta( $term['term_id'], 'icon', $icon ); + } + if ( ! empty( $client_uri ) ) { + add_term_meta( $term['term_id'], 'client_uri', $client_uri ); + } + add_term_meta( $term['term_id'], 'last_modified', time() ); return array_filter( array( From d64ad759bfd3d6cf410f6eeb02ac173453c6c413 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 25 Aug 2024 20:28:36 +0000 Subject: [PATCH 4/5] Return client_uri when appropriate --- includes/class-indieauth-client-taxonomy.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/class-indieauth-client-taxonomy.php b/includes/class-indieauth-client-taxonomy.php index bdda6e5..a478a06 100755 --- a/includes/class-indieauth-client-taxonomy.php +++ b/includes/class-indieauth-client-taxonomy.php @@ -215,6 +215,7 @@ public static function get_client( $url = null ) { 'name' => $term->name, 'id' => $term->term_id, 'icon' => get_term_meta( $term->term_id, 'icon', true ), + 'uri' => get_term_meta( $term->term_id, 'client_uri', true ), 'last_modified' => get_term_meta( $term->term_id, 'last_modified', true ), ); } @@ -248,6 +249,7 @@ public static function get_client( $url = null ) { 'name' => $term->name, 'id' => $term->term_id, 'icon' => get_term_meta( $term->term_id, 'icon', true ), + 'uri' => get_term_meta( $term->term_id, 'client_uri', true ), 'last_modified' => get_term_meta( $term->term_id, 'last_modified', true ), ); } From 30f6bf9ee66c201c26110410b890a230d0427ffb Mon Sep 17 00:00:00 2001 From: David Shanske Date: Mon, 26 Aug 2024 02:02:45 +0000 Subject: [PATCH 5/5] Bump version --- indieauth.php | 2 +- languages/indieauth.pot | 24 ++++++++++++++++-------- readme.md | 6 +++++- readme.txt | 6 +++++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/indieauth.php b/indieauth.php index 72bf5f3..f2cb45e 100644 --- a/indieauth.php +++ b/indieauth.php @@ -3,7 +3,7 @@ * Plugin Name: IndieAuth * Plugin URI: https://github.com/indieweb/wordpress-indieauth/ * Description: IndieAuth is a way to allow users to use their own domain to sign into other websites and services - * Version: 4.5.1 + * Version: 4.5.2 * Author: IndieWeb WordPress Outreach Club * Author URI: https://indieweb.org/WordPress_Outreach_Club * License: MIT diff --git a/languages/indieauth.pot b/languages/indieauth.pot index 03ed858..3905ed5 100644 --- a/languages/indieauth.pot +++ b/languages/indieauth.pot @@ -2,9 +2,9 @@ # This file is distributed under the MIT. msgid "" msgstr "" -"Project-Id-Version: IndieAuth 4.5.1\n" +"Project-Id-Version: IndieAuth 4.5.2\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/indieauth\n" -"POT-Creation-Date: 2024-08-14 00:32:52+00:00\n" +"POT-Creation-Date: 2024-08-26 02:02:31+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -375,19 +375,19 @@ msgstr "" msgid "Invalid access token" msgstr "" -#: includes/class-indieauth-client-discovery.php:38 +#: includes/class-indieauth-client-discovery.php:39 msgid "Failed to Retrieve IndieAuth Client Details " msgstr "" -#: includes/class-indieauth-client-discovery.php:69 +#: includes/class-indieauth-client-discovery.php:70 msgid "Failed to Retrieve Client Details" msgstr "" -#: includes/class-indieauth-client-discovery.php:100 +#: includes/class-indieauth-client-discovery.php:101 msgid "Discovery Has Returned an Empty JSON Document" msgstr "" -#: includes/class-indieauth-client-discovery.php:103 +#: includes/class-indieauth-client-discovery.php:104 msgid "No Client ID Found in JSON Client Metadata" msgstr "" @@ -399,11 +399,19 @@ msgstr "" msgid "IndieAuth Client Application Icon" msgstr "" -#: includes/class-indieauth-client-taxonomy.php:207 +#: includes/class-indieauth-client-taxonomy.php:88 +msgid "IndieAuth Client Application URI" +msgstr "" + +#: includes/class-indieauth-client-taxonomy.php:100 +msgid "Last Modified Client Timestamp" +msgstr "" + +#: includes/class-indieauth-client-taxonomy.php:238 msgid "No Term Found" msgstr "" -#: includes/class-indieauth-client-taxonomy.php:211 +#: includes/class-indieauth-client-taxonomy.php:242 msgid "Multiple Terms Found" msgstr "" diff --git a/readme.md b/readme.md index d2adc52..69eaaba 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ **Requires at least:** 4.9.9 **Requires PHP:** 7.2 **Tested up to:** 6.6 -**Stable tag:** 4.5.1 +**Stable tag:** 4.5.2 **License:** MIT **License URI:** http://opensource.org/licenses/MIT **Donate link:** https://opencollective.com/indieweb @@ -189,6 +189,10 @@ In version 2.0, we added an IndieAuth endpoint to this plugin, which previously Project and support maintained on github at [indieweb/wordpress-indieauth](https://github.com/indieweb/wordpress-indieauth). +### 4.5.2 ### +* Fix issue with loop on adding new clients +* Store client_uri and last modified date for new clients. + ### 4.5.1 ### * Fix issue with failure if logo_uri is not a URL * Fix conflict with Jetpack plugin due not returning error property (props @janboddez) diff --git a/readme.txt b/readme.txt index da1fe96..781c445 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: IndieAuth, IndieWeb, IndieWebCamp, login Requires at least: 4.9.9 Requires PHP: 7.2 Tested up to: 6.6 -Stable tag: 4.5.1 +Stable tag: 4.5.2 License: MIT License URI: http://opensource.org/licenses/MIT Donate link: https://opencollective.com/indieweb @@ -189,6 +189,10 @@ In version 2.0, we added an IndieAuth endpoint to this plugin, which previously Project and support maintained on github at [indieweb/wordpress-indieauth](https://github.com/indieweb/wordpress-indieauth). += 4.5.2 = +* Fix issue with loop on adding new clients +* Store client_uri and last modified date for new clients. + = 4.5.1 = * Fix issue with failure if logo_uri is not a URL * Fix conflict with Jetpack plugin due not returning error property (props @janboddez)