Skip to content

xabbuh/oauth1-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OAuth1 Authentication for HTTPlug

Build Status Scrutinizer Code Quality

Sign PSR-7 requests using OAuth1 when using them with HTTPlug clients.

Installation

Install the OAuth1 integration using Composer:

$ composer require xabbuh/oauth1-authentication:^1.0

Usage

  1. Configure the request signer with your consumer key and secret:

    use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerKey;
    use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerSecret;
    use ApiClients\Tools\Psr7\Oauth1\RequestSigning\RequestSigner;
    
    $requestSigner = new RequestSigner(
        new ConsumerKey('consumer_key'),
        new ConsumerSecret('consumer_secret')
    );

    You can also optionally specify the hash algorithm to use. Read more about that in the api-clients/psr7-oauth1 documentation.

  2. Set up the OAuth1 authentication passing the configured request signer together with your access token and token secret:

    // ...
    use ApiClients\Tools\Psr7\Oauth1\Definition\AccessToken;
    use ApiClients\Tools\Psr7\Oauth1\Definition\TokenSecret;
    use Xabbuh\Http\Authentication\OAuth1;
    
    // ...
    
    $oauth = new OAuth1(
        $requestSigner,
        new AccessToken('access_token'),
        new TokenSecret('token_secret')
    );
  3. Use the configured authentication with the authentication plugin:

    // ...
    use Http\Discovery\HttpClientDiscovery;
    use Http\Client\Common\PluginClient;
    use Http\Client\Common\Plugin\AuthenticationPlugin;
    
    // ...
    
    $authenticationPlugin = new AuthenticationPlugin($oauth);
    
    $pluginClient = new PluginClient(
        HttpClientDiscovery::find(),
        [$authenticationPlugin]
    );

About

OAuth1 authentication for the HTTPlug library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages