oauth2-client icon indicating copy to clipboard operation
oauth2-client copied to clipboard

Basic example improvements

Open murraycollingwood opened this issue 2 years ago • 2 comments
trafficstars

Hello

I have been working with this page for a few weeks now: https://oauth2-client.thephpleague.com/usage/ I would like to suggest a couple of modifications:

        // Try to get an access token using the authorization code grant.
        $accessToken = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

        // We have an access token, which we may use in authenticated
        // requests against the service provider's API.
        echo 'Access Token: ' . $accessToken->getToken() . "<br>";
        echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "<br>";
        echo 'Expired in: ' . $accessToken->getExpires() . "<br>";
        echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>";

Can this be changed to:

        // Try to get an access token using the authorization code grant.
        $tokens = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

        // We have an access token, which we may use in authenticated
        // requests against the service provider's API.
        echo 'Access Token: ' . $tokens->getToken() . "<br>";
        echo 'Refresh Token: ' . $tokens->getRefreshToken() . "<br>";
        echo 'Expired in: ' . $tokens->getExpires() . "<br>";
        echo 'Already expired? ' . ($tokens->hasExpired() ? 'expired' : 'not expired') . "<br>";

murraycollingwood avatar Nov 15 '23 20:11 murraycollingwood

In what was is it an improvement?

zerkms avatar Feb 23 '24 04:02 zerkms

It seems that variable $accessToken contains both the access token and the refresh token, so it should've been called $oauthTokens instead.

codespearhead avatar Jun 25 '24 20:06 codespearhead