PHP code example of stuki / oauth2-simple-client

1. Go to this page and download the library: Download stuki/oauth2-simple-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stuki / oauth2-simple-client example snippets


use Stuki\OAuth2\Client;

    public function LoginAction()
    {
        $config = $this->getServiceLocator()->get('Config');

        $provider = new Client\Provider\Meetup(array(
            'clientId' => $config['meetup']['key'],
            'clientSecret' => $config['meetup']['secret'],
            'redirectUri' => $config['meetup']['redirect'],
        ));

        if ( ! $this->params()->fromQuery('code')) {
            // No authorization code; send user to get one
            // Some providers support and/or            $container = new Container('oauth2');
            $container->accessToken = $token->accessToken;
            $container->refreshToken = $token->refreshToken;

            // Redirect to save session
            return $this->plugin('redirect')->toRoute('member');
        }
    }

use Stuki\OAuth2\Client;

$provider = new Client\Provider\<ProviderName>(array(
    'clientId'  =>  'id',
    'clientSecret'  =>  'secret',
    'redirectUri'   =>  'https://your-registered-redirect-uri/'
));

$grant = new Client\Grant\RefreshToken();
$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]);