Changeset 3320377
- Timestamp:
- 07/01/2025 07:57:49 AM (9 months ago)
- Location:
- patreon-connect/trunk
- Files:
-
- 5 edited
-
CHANGELOG.md (modified) (1 diff)
-
classes/patreon_oauth.php (modified) (1 diff)
-
classes/patreon_wordpress.php (modified) (4 diffs)
-
patreon.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
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 1 5 = 1.9.11 = 2 6 -
patreon-connect/trunk/classes/patreon_oauth.php
r3316345 r3320377 101 101 } 102 102 103 if (isset($response_decoded['scope'])) { 104 $result['scope'] = $response_decoded['scope']; 105 } 106 103 107 $result['http_status_code'] = $status_code; 104 108 -
patreon-connect/trunk/classes/patreon_wordpress.php
r3316345 r3320377 449 449 } 450 450 451 $should_refresh_tokens = false; 452 451 453 if (isset($user_response['errors']) && is_array($user_response['errors'])) { 452 454 foreach ($user_response['errors'] as $error) { 453 455 if (1 == $error['code']) { 454 if (self::refresh_creator_access_token()) { 455 return $api_client->fetch_creator_info(); 456 } 456 $should_refresh_tokens = true; 457 457 } 458 458 } 459 459 } 460 460 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; 462 472 } 463 473 … … 490 500 $tokens = $oauth_client->refresh_token($refresh_token, site_url().'/patreon-authorization/', true); 491 501 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 492 515 if (isset($tokens['refresh_token']) && isset($tokens['access_token'])) { 516 update_option('patreon-creators-access-token', $tokens['access_token']); 493 517 update_option('patreon-creators-refresh-token', $tokens['refresh_token']); 494 update_option('patreon-creators-access-token', $tokens['access_token']);495 518 delete_option('patreon-wordpress-app-credentials-failure'); 496 } 497 498 return $tokens ?: false; 519 520 return $tokens; 521 } 522 523 return false; 499 524 } finally { 500 525 delete_transient($lock_key); … … 515 540 516 541 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()) { 521 543 return true; 522 544 } … … 1351 1373 { 1352 1374 // 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); 1380 1379 $creator_response = $api_client->fetch_creator_info(); 1380 1381 $creator_access = false; 1381 1382 1382 1383 if (isset($creator_response['included'][0]['id']) and '' != $creator_response['included'][0]['id']) { 1383 1384 // Got creator id. Credentials must be valid 1384 // Success - set flag1385 1386 1385 $creator_access = true; 1387 1386 } 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 } 1399 1411 } 1400 1412 -
patreon-connect/trunk/patreon.php
r3316345 r3320377 5 5 Plugin URI: https://www.patreon.com/apps/wordpress 6 6 Description: Patron-only content, directly on your website. 7 Version: 1.9.1 17 Version: 1.9.12 8 8 Author: Patreon <platform@patreon.com> 9 9 Author URI: https://patreon.com … … 70 70 define('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'); 71 71 define('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.1 1');72 define('PATREON_WORDPRESS_VERSION', '1.9.12'); 73 73 define('PATREON_WORDPRESS_BETA_STRING', ''); 74 74 define('PATREON_WORDPRESS_PLUGIN_SLUG', plugin_basename(__FILE__)); -
patreon-connect/trunk/readme.txt
r3316345 r3320377 5 5 Requires PHP: 7.4 6 6 Tested up to: 6.8.1 7 Stable tag: 1.9.1 17 Stable tag: 1.9.12 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 79 79 80 80 == Upgrade Notice == 81 82 = 1.9.12 = 83 84 * Fixed: Fixed several bugs with creator token refresh. 81 85 82 86 = 1.9.11 = … … 561 565 == Changelog == 562 566 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.