zacharyrankin/hmac-auth

Simple token authentication for PHP

v0.2 2015-06-13 20:18 UTC

This package is not auto-updated.

Last update: 2024-04-13 15:23:07 UTC


README

Simple token authentication for PHP

Usage

Require via Composer

composer require zacharyrankin/hmac-auth

Client

use zacharyrankin\hmac_auth\Authenticator;
use zacharyrankin\hmac_auth\Client;

$auth = new Authenticator;
$token = $auth->createToken(new Client('some user', 'user secret'));
header('X-Authorization-Token: ' . $token);

Server

use zacharyrankin\hmac_auth\Authenticator;
use zacharyrankin\hmac_auth\Client;

$auth = new Authenticator
$auth->authenticate(
  $_SERVER['HTTP_X_AUTHORIZATION_TOKEN'],
  function ($clientId) {
    return new Client($clientId, SomeModel::findSecret($clientId));
  },
  300 // expiration in seconds
);