Skip to content

Commit ad9316f

Browse files
author
HugoMartineau
committed
fix refresh token
1 parent 3457b34 commit ad9316f

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

cron/helloasso-woocommerce-cron.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
// Durée de validité du refresh token : 30 jours en secondes
4+
define('HELLOASSO_REFRESH_TOKEN_LIFETIME', 30 * 24 * 60 * 60); // 2592000 secondes
5+
36
function hello_asso_cron_refresh_token()
47
{
58
helloasso_refresh_token_asso();
@@ -47,8 +50,8 @@ function helloasso_refresh_token_asso()
4750
if (isset($data->access_token)) {
4851
update_option('helloasso_access_token_asso', $data->access_token);
4952
update_option('helloasso_refresh_token_asso', $data->refresh_token);
50-
update_option('helloasso_token_expires_in_asso', $data->expires_in);
51-
update_option('helloasso_refresh_token_expires_in_asso', time() + 2629800);
53+
update_option('helloasso_token_expires_in_asso', time() + $data->expires_in);
54+
update_option('helloasso_refresh_token_expires_in_asso', time() + HELLOASSO_REFRESH_TOKEN_LIFETIME);
5255
return $data->access_token;
5356
} else {
5457
return null;

helloasso-api/helloasso-woocommerce-api.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
exit; //Exit if accessed directly
44
}
55

6+
// Durée de validité du refresh token : 30 jours en secondes
7+
define('HELLOASSO_REFRESH_TOKEN_LIFETIME', 30 * 24 * 60 * 60); // 2592000 secondes
8+
69
function helloasso_get_oauth_token($client_id, $client_secret, $api_url)
710
{
811
helloasso_log_debug('Vérification du token OAuth2', array(
@@ -59,8 +62,8 @@ function helloasso_get_oauth_token($client_id, $client_secret, $api_url)
5962
if (isset($data->access_token)) {
6063
update_option('helloasso_access_token', $data->access_token);
6164
update_option('helloasso_refresh_token', $data->refresh_token);
62-
update_option('helloasso_token_expires_in', $data->expires_in);
63-
update_option('helloasso_refresh_token_expires_in', time() + 2629800);
65+
update_option('helloasso_token_expires_in', time() + $data->expires_in);
66+
update_option('helloasso_refresh_token_expires_in', time() + HELLOASSO_REFRESH_TOKEN_LIFETIME);
6467

6568
helloasso_log_info('Token OAuth2 rafraîchi avec succès', array(
6669
'new_token_preview' => substr($data->access_token, 0, 10) . '...',
@@ -112,8 +115,8 @@ function helloasso_get_oauth_token($client_id, $client_secret, $api_url)
112115
if (isset($data->access_token)) {
113116
add_option('helloasso_access_token', $data->access_token);
114117
add_option('helloasso_refresh_token', $data->refresh_token);
115-
add_option('helloasso_token_expires_in', $data->expires_in);
116-
add_option('helloasso_refresh_token_expires_in', time() + 2629800);
118+
add_option('helloasso_token_expires_in', time() + $data->expires_in);
119+
add_option('helloasso_refresh_token_expires_in', time() + HELLOASSO_REFRESH_TOKEN_LIFETIME);
117120

118121
helloasso_log_info('Nouveau token OAuth2 obtenu avec succès', array(
119122
'token_preview' => substr($data->access_token, 0, 10) . '...',

wc-api/helloasso-woocommerce-wc-api.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
exit; //Exit if accessed directly
44
}
55

6+
// Durée de validité du refresh token : 30 jours en secondes
7+
define('HELLOASSO_REFRESH_TOKEN_LIFETIME', 30 * 24 * 60 * 60); // 2592000 secondes
8+
69
add_action('woocommerce_api_helloasso', 'helloasso_endpoint');
710
function helloasso_endpoint()
811
{
@@ -96,8 +99,8 @@ function helloasso_endpoint()
9699
add_option('helloasso_organization_slug', $data->organization_slug);
97100
add_option('helloasso_access_token_asso', $data->access_token);
98101
add_option('helloasso_refresh_token_asso', $data->refresh_token);
99-
add_option('helloasso_token_expires_in_asso', $data->expires_in);
100-
add_option('helloasso_refresh_token_expires_in_asso', time() + 2629800);
102+
add_option('helloasso_token_expires_in_asso', time() + $data->expires_in);
103+
add_option('helloasso_refresh_token_expires_in_asso', time() + HELLOASSO_REFRESH_TOKEN_LIFETIME);
101104

102105
$urlNotif = $api_url . 'v5/partners/me/api-notifications/organizations/' . $data->organization_slug;
103106

0 commit comments

Comments
 (0)