2017 © Pedro Peláez
 

library ght-api-authenticator

GHT API Authenticator

image

greenhollowtech/ght-api-authenticator

GHT API Authenticator

  • Friday, January 1, 2016
  • by iisisrael
  • Repository
  • 0 Watchers
  • 0 Stars
  • 23 Installations
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

GHT API Authenticator

The GHT API Authenticator provides authentication in API applications., (*1)

Installation

To install with Composer, run composer require greenhollowtech/ght-api-authenticator., (*2)

Usage

The authenticator is designed to be used in counterpart with the GHT API Client, parsing and validating requests that contain user, key and hash values passed via the Authorization header., (*3)

The simplest use of the authenticator is to validate a known key and secret against the current HTTP request:, (*4)

use GHT\ApiAuthenticator\GHTApiAuthenticator;

// Determine the expected API key and secret used by the client making the request
$apiKey = 'someKnownKey';
$apiSecret = 'someKnownSecretNotPassedInTheRequest';

// Validate the credentials in the current request
try {
    GHTApiAuthenticator::validate($apiKey, $apiSecret);
}
catch (\Exception $e) {
    // Don't let this hacker in!
    error_log('Request failed. ' . $e->getMessage());
    return;
}

// The request is validated, do something nice...

Quite possibly, your application will have API keys and secrets stored for each user. You can first grab the Authorization credentials to look up the requesting user's key and secret before validating the request., (*5)

use GHT\ApiAuthenticator\GHTApiAuthenticator;

// Get the requesting user's credentials
try {
    $credentials = GHTApiAuthenticator::getCredentials();
}
catch (\Exception $e) {
    // Authorization header is missing!
    error_log('Request failed. ' . $e->getMessage());
    return;
}

// Look up the User with whatever method is provided by your application
$user = $userRepository->findByUsername($credentials['api-user']);
// (you would validate your User object here, too, eh?)

// Validate the credentials in the current request with the User's key and secret
try {
    GHTApiAuthenticator::validate($user->getApiKey(), $user->getApiSecret());
    ...

Security Holes

You can override the credentials used in the validation, the request itself, and the Authorization header requirement to allow credentials passed via POST values, the GET query string, et cetera. See the documentation in the GHTApiAuthenticator class for all the nitty gritty. The authenticator does not force you to be safe and secure - manipulate at your own risk., (*6)

The Versions

01/01 2016

dev-master

9999999-dev https://bitbucket.org/greenhollowtech/ght-api-authenticator

GHT API Authenticator

  Sources   Download

MIT

The Requires

 

The Development Requires

api authentication php authenticator

01/01 2016

2.0.0

2.0.0.0 https://bitbucket.org/greenhollowtech/ght-api-authenticator

GHT API Authenticator

  Sources   Download

MIT

The Requires

 

The Development Requires

api authentication php authenticator

01/01 2016

1.0.0

1.0.0.0 https://bitbucket.org/greenhollowtech/ght-api-authenticator

GHT API Authenticator

  Sources   Download

MIT

The Requires

 

The Development Requires

api authentication php authenticator