sarahman / oauth-tokens-client by sarahman

This package handles the oauth tokens with caching functionality.
11
0
0
Package Data
Maintainer Username: sarahman
Maintainer Contact: aabid048@gmail.com (Syed Abidur Rahman)
Package Create Date: 2025-06-09
Package Last Update: 2025-07-08
Language: PHP
License: MIT
Last Refreshed: 2025-07-09 03:00:03
Package Statistics
Total Downloads: 11
Monthly Downloads: 11
Daily Downloads: 9
Total Stars: 0
Total Watchers: 0
Total Forks: 0
Total Open Issues: 0

Oauth Tokens Client

Latest Version on Packagist Build Status Scrutinizer Code Quality StyleCI Total Downloads License PHP Version Require

PHP library built by PSR-16 simple cache interface can be used in any php project or it has laravel support to install through its service provider.

Installation

  • Step 1: You can install the package via composer:
composer require sarahman/oauth-tokens-client
  • Step 2.a: Next, for the laravel projects, we can load its service provider:
// app/config/app.php
'providers' => [
    ...
    'Sarahman\OauthTokensClient\OauthTokensClientServiceProvider',
];

You can publish the config file with:

php artisan config:publish sarahman/oauth-tokens-client

This is the contents of the published config file:


return array(
    'TOKEN_PREFIXES'   => array(
        'ACCESS'  => 'oauth_access_token',
        'REFRESH' => 'oauth_refresh_token',
    ),
    'LOCK_KEY'         => 'oauth_token_refresh_lock',
    'OAUTH_CREDENTIAL' => array(
        'GRANT_TYPE'    => 'client_credentials',
        'TOKEN_URL'     => null,
        'REFRESH_URL'   => null,
        'CLIENT_ID'     => null,
        'CLIENT_SECRET' => null,
        'USERNAME'      => null,
        'PASSWORD'      => null,
        'SCOPE'         => '',
    ),
);

Note: If we use password grant, then we must set USERNAME and PASSWORD config keys.

  • Step 2.b: for the regular php projects, we might directly add these following codes:

require "vendor/autoload.php";

$clientConfig = array(
    'TOKEN_PREFIXES'   => array(
        'ACCESS'  => 'oauth_access_token',
        'REFRESH' => 'oauth_refresh_token',
    ),
    'LOCK_KEY'         => 'oauth_token_refresh_lock',
    'OAUTH_CREDENTIAL' => array(
        'GRANT_TYPE'    => 'client_credentials',
        'TOKEN_URL'     => 'http://localhost/grant-token',
        'REFRESH_URL'   => 'http://localhost/refresh-token',
        'CLIENT_ID'     => 1,
        'CLIENT_SECRET' => '**********',
        'SCOPE'         => '',
    ),
);

$client = new OAuthClient(
    new Client,
    <CACHE_STORE>,
    $clientConfig['OAUTH_CREDENTIAL'],
    $clientConfig['TOKEN_PREFIXES'],
    $clientConfig['LOCK_KEY']
);

// Set Cache key.
$data = array(
    'sample' => 'data',
    'another' => 'data',
);

$response = $client->request('POST', 'http://localhost/get-user', $data);

var_dump($response);

Testing

You might go to the project directory and run the following command to run test code.

composer test

Contribution

Feel free to contribute in this library. Please make your changes and send us pull requests.

Security Issues

If you discover any security related issues, please feel free to create an issue in the issue tracker or write us at aabid048@gmail.com.

License

The MIT License (MIT). Please see License File for more information.