Plugin Directory

Changeset 3320377


Ignore:
Timestamp:
07/01/2025 07:57:49 AM (9 months ago)
Author:
patreon
Message:

1.9.12 release

Location:
patreon-connect/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • patreon-connect/trunk/CHANGELOG.md

    r3316345 r3320377  
     1= 1.9.12 =
     2
     3* Fixed: Fixed several bugs with creator token refresh.
     4
    15= 1.9.11 =
    26
  • patreon-connect/trunk/classes/patreon_oauth.php

    r3316345 r3320377  
    101101        }
    102102
     103        if (isset($response_decoded['scope'])) {
     104            $result['scope'] = $response_decoded['scope'];
     105        }
     106
    103107        $result['http_status_code'] = $status_code;
    104108
  • patreon-connect/trunk/classes/patreon_wordpress.php

    r3316345 r3320377  
    449449        }
    450450
     451        $should_refresh_tokens = false;
     452
    451453        if (isset($user_response['errors']) && is_array($user_response['errors'])) {
    452454            foreach ($user_response['errors'] as $error) {
    453455                if (1 == $error['code']) {
    454                     if (self::refresh_creator_access_token()) {
    455                         return $api_client->fetch_creator_info();
    456                     }
     456                    $should_refresh_tokens = true;
    457457                }
    458458            }
    459459        }
    460460
    461         return $user_response;
     461        if ($should_refresh_tokens) {
     462            if ($token_data = self::refresh_creator_access_token()) {
     463                $api_client = new Patreon_API($token_data['access_token']);
     464
     465                return $api_client->fetch_creator_info();
     466            }
     467        } else {
     468            return $user_response;
     469        }
     470
     471        return false;
    462472    }
    463473
     
    490500            $tokens = $oauth_client->refresh_token($refresh_token, site_url().'/patreon-authorization/', true);
    491501
     502            if (isset($tokens['scope'])) {
     503                update_option('patreon-creators-access-token-scope', $tokens['scope']);
     504            }
     505
     506            $expires_in = PatreonTimeConstants::DAY_S * 7;
     507
     508            if (isset($tokens['expires_in'])) {
     509                $expires_in = $tokens['expires_in'];
     510            }
     511
     512            $new_expiration = time() + $expires_in;
     513            update_option('patreon-creators-access-token-scope', $new_expiration);
     514
    492515            if (isset($tokens['refresh_token']) && isset($tokens['access_token'])) {
     516                update_option('patreon-creators-access-token', $tokens['access_token']);
    493517                update_option('patreon-creators-refresh-token', $tokens['refresh_token']);
    494                 update_option('patreon-creators-access-token', $tokens['access_token']);
    495518                delete_option('patreon-wordpress-app-credentials-failure');
    496             }
    497 
    498             return $tokens ?: false;
     519
     520                return $tokens;
     521            }
     522
     523            return false;
    499524        } finally {
    500525            delete_transient($lock_key);
     
    515540
    516541        if (!$expiration or $expiration <= (time() + (60 * 60 * 24 * 7))) {
    517             if ($tokens = self::refresh_creator_access_token()) {
    518                 update_option('patreon-creators-refresh-token-expiration', time() + $tokens['expires_in']);
    519                 update_option('patreon-creators-access-token-scope', $tokens['scope']);
    520 
     542            if (self::refresh_creator_access_token()) {
    521543                return true;
    522544            }
     
    13511373    {
    13521374        // Just attempts to connect to API with given credentials, and returns result
    1353 
    1354         // Currently can verify only if creator's access token and refresh token are false. If the access token is false and refresh token is not, the system already refreshes the access token automatically. If only refresh token is false, then the existing correct access token will check true. In future a better check should be implemented
    1355 
    1356         $api_client = new Patreon_API(get_option('patreon-creators-access-token', false));
    1357         $creator_response = $api_client->fetch_creator_info();
    1358 
    1359         $creator_access = false;
    1360         $client_access = false;
    1361 
    1362         if (isset($creator_response['included'][0]['id']) and '' != $creator_response['included'][0]['id']) {
    1363             // Got creator id. Credentials must be valid
    1364 
    1365             // Success - set flag
    1366             // update_option( 'patreon-wordpress-app-credentials-success', 1 );
    1367 
    1368             $creator_access = true;
    1369         }
    1370 
    1371         // Try to do a creator's token refresh
    1372 
    1373         if (!$creator_access and $tokens = self::refresh_creator_access_token()) {
    1374             update_option('patreon-creators-refresh-token-expiration', time() + $tokens['expires_in']);
    1375             update_option('patreon-creators-access-token-scope', $tokens['scope']);
    1376 
    1377             // Try again:
    1378 
    1379             $api_client = new Patreon_API(get_option('patreon-creators-access-token', false));
     1375        $creator_access_token = get_option('patreon-creator-access-token', false);
     1376
     1377        if ($creator_access_token) {
     1378            $api_client = new Patreon_API($creator_access_token);
    13801379            $creator_response = $api_client->fetch_creator_info();
     1380
     1381            $creator_access = false;
    13811382
    13821383            if (isset($creator_response['included'][0]['id']) and '' != $creator_response['included'][0]['id']) {
    13831384                // Got creator id. Credentials must be valid
    1384                 // Success - set flag
    1385 
    13861385                $creator_access = true;
    13871386            }
    1388         }
    1389 
    1390         // Here some check for client id and secret may be entered in future - currently only checks creator access token
    1391 
    1392         if ($creator_access) {
    1393             // Successfully used creator token, mark the integration credentials
    1394             // valid.
    1395             update_option('patreon-wordpress-app-credentials-success', 1);
    1396             delete_option('patreon-wordpress-app-credentials-failure');
    1397 
    1398             return;
     1387
     1388            // Try to do a creator's token refresh
     1389            if (!$creator_access and $tokens = self::refresh_creator_access_token()) {
     1390                // Try again:
     1391                $api_client = new Patreon_API($tokens['access_token']);
     1392                $creator_response = $api_client->fetch_creator_info();
     1393
     1394                if (isset($creator_response['included'][0]['id']) and '' != $creator_response['included'][0]['id']) {
     1395                    // Got creator id. Credentials must be valid
     1396                    // Success - set flag
     1397                    $creator_access = true;
     1398                }
     1399            }
     1400
     1401            // Here some check for client id and secret may be entered in future - currently only checks creator access token
     1402
     1403            if ($creator_access) {
     1404                // Successfully used creator token, mark the integration credentials
     1405                // valid.
     1406                update_option('patreon-wordpress-app-credentials-success', 1);
     1407                delete_option('patreon-wordpress-app-credentials-failure');
     1408
     1409                return;
     1410            }
    13991411        }
    14001412
  • patreon-connect/trunk/patreon.php

    r3316345 r3320377  
    55Plugin URI: https://www.patreon.com/apps/wordpress
    66Description: Patron-only content, directly on your website.
    7 Version: 1.9.11
     7Version: 1.9.12
    88Author: Patreon <platform@patreon.com>
    99Author URI: https://patreon.com
     
    7070define('PATREON_NO_LOCKING_LEVEL_SET_FOR_THIS_POST', 'Post is already public. If you would like to lock this post, please set a pledge level for it');
    7171define('PATREON_NO_POST_ID_TO_UNLOCK_POST', 'Sorry - could not get the post id for this locked post');
    72 define('PATREON_WORDPRESS_VERSION', '1.9.11');
     72define('PATREON_WORDPRESS_VERSION', '1.9.12');
    7373define('PATREON_WORDPRESS_BETA_STRING', '');
    7474define('PATREON_WORDPRESS_PLUGIN_SLUG', plugin_basename(__FILE__));
  • patreon-connect/trunk/readme.txt

    r3316345 r3320377  
    55Requires PHP: 7.4
    66Tested up to: 6.8.1
    7 Stable tag: 1.9.11
     7Stable tag: 1.9.12
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    7979
    8080== Upgrade Notice ==
     81
     82= 1.9.12 =
     83
     84* Fixed: Fixed several bugs with creator token refresh.
    8185
    8286= 1.9.11 =
     
    561565== Changelog ==
    562566
    563 = 1.9.11 =
    564 
    565 * Fixed: Resolved an issue where the plugin would repeatedly attempt to refresh
    566   expired or invalid OAuth tokens, resulting in continuous 401 responses. This
    567   update prevents unnecessary token refresh attempts and reduces the risk of
    568   rate limiting by the Patreon API.
     567= 1.9.12 =
     568
     569* Fixed: Fixed several bugs with creator token refresh.
Note: See TracChangeset for help on using the changeset viewer.