iamstuartwilson / strava

PHP Class for the Strava API (v3)
MIT License
120 stars 26 forks source link

Automaticcaly set token after successful exchange? #31

Closed Niellles closed 1 year ago

Niellles commented 6 years ago

Is there a reason for not automatically setting the access_token after a successful token exchange? I'd like (to implement) an (optional) automatic assignment of private $accessToken after a successful token exchange.

$code = '123abc';
$token = $api->tokenExchange($code);
$api->setAccessToken($token);

Could be:

$code = '123abc';
$token = $api->tokenExchange($code, true); // To automatically store the token if successful.

Although I'd probably want the default for the 2nd argument to be true and make not assigning it automatically the optional version. This shouldn't break backward compatibility.

Alternatively setAccessToken() could attempt to get a token if a code instead of a token is supplied. I don't think that's the way to go though; you'd have to differentiate between tokens and codes, this would probably become a giant mess. Only pro is that I find this method name is a little bit more appropriate than tokenExchange().

Any thoughts?