thephpleague / oauth2-client

Easy integration with OAuth 2.0 service providers.

Home Page:http://oauth2-client.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Basic example improvements (2)

murraycollingwood opened this issue · comments

Hello

I've been working with your oauth2 client example for a few weeks and have some improvements that would have helped me when I started.

https://oauth2-client.thephpleague.com/usage/

$existingAccessToken = getAccessTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
    $newAccessToken = $provider->getAccessToken('refresh_token', [
        'refresh_token' => $existingAccessToken->getRefreshToken()
    ]);

    // Purge old access token and store new access token to your data store.
}

Can the above be changed to:

$existingAccessToken = getAccessTokenFromYourDataStore();
$existingRefreshToken = getRefreshTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
    $tokens = $provider->getAccessToken('refresh_token', [
        'refresh_token' => $existingRefreshToken
    ]);

    // Purge old access token and store new access token to your data store.
    saveNewAccessTokenToYourDataStore($tokens->getToken());
    saveNewExpiryToYourDataStore($tokens->getExpiry());
}