Skip to content
New issue

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

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

Already on GitHub? # to your account

Basic example improvements #1017

Closed
murraycollingwood opened this issue Nov 15, 2023 · 2 comments
Closed

Basic example improvements #1017

murraycollingwood opened this issue Nov 15, 2023 · 2 comments

Comments

@murraycollingwood
Copy link
Contributor

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>";
@zerkms
Copy link

zerkms commented Feb 23, 2024

In what was is it an improvement?

@codespearhead
Copy link

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

@ramsey ramsey closed this as completed in ba37ec1 Dec 11, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants