Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic example improvements (2) #1018

Open
murraycollingwood opened this issue Nov 15, 2023 · 0 comments
Open

Basic example improvements (2) #1018

murraycollingwood opened this issue Nov 15, 2023 · 0 comments

Comments

@murraycollingwood
Copy link

murraycollingwood commented Nov 15, 2023

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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant