Patreon / patreon-php

Interact with the Patreon API via OAuth
Apache License 2.0
145 stars 41 forks source link

Same data returned from diffrent access tokens #98

Open Asis2019 opened 1 year ago

Asis2019 commented 1 year ago

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