sscarpa / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

No way to access auth class from apiClient #52

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I noticed that the php client is automatically refreshing the token if it feels 
necessary using the OAuth2 refreshToken method.  I would like to call this 
myself and store the resultant refresh token if the current access token is 
expired.

Unfortunately, I can't seem to figure out a way to access the OAuth2 class 
stored in the static $auth variable under the ApiClient.  Is there a way to 
access this I am missing? Or is there a better way to handle the refresh 
process that doesn't involve trying to call refreshToken manually?

Original issue reported on code.google.com by davidcroda on 20 Dec 2011 at 4:29

GoogleCodeExporter commented 8 years ago
I ran into the same issue... It would be really nice if we could just specify 
an optional callback function that is triggered when the token is updated 
successfully via apiOAuth2::refreshToken()

For example after this line:
$this->accessToken['created'] = time();

We could have something like:
if (isset($this->refreshTokenCallback)) 
call_user_func($this->refreshTokenCallback, $this);

Original comment by digitalp...@gmail.com on 20 Dec 2011 at 11:09

GoogleCodeExporter commented 8 years ago
A callback function would be perfect

Original comment by davidcroda on 20 Dec 2011 at 1:40

GoogleCodeExporter commented 8 years ago
On second thought, I would prefer to be able to call the refreshToken method 
manually.  There is some state related information (ie. what object the access 
token belongs to in the database) which would not be available with just the 
Auth object.

Original comment by davidcroda on 20 Dec 2011 at 5:04

GoogleCodeExporter commented 8 years ago

Original comment by chirags@google.com on 3 Jan 2012 at 6:12

GoogleCodeExporter commented 8 years ago
Hey David,

Thank you for reporting this! 
Changes as of r312.
1) refreshToken is no longer protected inside apiOAuth2 and exposed.
2) You can now access the auth class from apiClient. $client->getAuth();
3) You can also call $client->refreshToken(), which will synchronously refresh 
the access token.

Original comment by chirags@google.com on 6 Jan 2012 at 9:05