patreon-php icon indicating copy to clipboard operation
patreon-php copied to clipboard

Same data returned from diffrent access tokens

Open Asis2019 opened this issue 1 year ago • 0 comments

I have a scenario where I needed to loop through all the stored tokens and retrieve some user data with them. The current cache implementation doesn't take the access token into account meaning that if you're calling the same endpoint (identity in my case) but with different access tokens, you will get the same data every time.

Current code:

// Construct request:
$api_request = $this->api_endpoint . $suffix;
		
// This identifies a unique request
$api_request_hash = md5($api_request);

Suggessted fix:

// Construct request:
$api_request = $this->api_endpoint . $suffix;
		
// This identifies a unique request
$api_request_hash = md5($api_request . $this->access_token);

If anyone is running into this issue you can empty the cache before making your request as a quick fix.

$client = new API($token); //Create client
API::$request_cache = null; //Empty the cache
$response = $client->get_data("identity"); //Make the request

Asis2019 avatar Feb 16 '23 07:02 Asis2019