https://github.com/datto/php-json-rpc-auth
Authentication & authorization extension for the JSON-RPC library
https://github.com/datto/php-json-rpc-auth
Last synced: 8 months ago
JSON representation
Authentication & authorization extension for the JSON-RPC library
- Host: GitHub
- URL: https://github.com/datto/php-json-rpc-auth
- Owner: datto
- License: lgpl-3.0
- Created: 2015-12-14T13:13:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-15T20:03:19.000Z (over 10 years ago)
- Last Synced: 2025-04-11T14:50:03.542Z (about 1 year ago)
- Language: PHP
- Size: 11.7 KB
- Stars: 4
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# JSON-RPC Auth Extension
This is an authentication and authorization extension for the [php-json-rpc](https://github.com/datto/php-json-rpc) library. It provides the ability to authorize JSON-RPC requests before they reach the endpoint.
Examples
--------
First write an authentication `Handler`:
```php
namespace Datto\JsonRpc\Auth;
use Datto\JsonRpc;
class BasicAuthHandler implements Handler
{
public function canHandle($method, $arguments)
{
return isset($_SERVER['PHP_AUTH_USER']);
}
public function authenticate($method, $arguments)
{
// Don't do this in production. Using '===' is vulnerable to timing attacks!
return $_SERVER['PHP_AUTH_USER'] === 'phil' && $_SERVER['PHP_AUTH_PW'] === 'superpass!';
}
}
```
Once you have that, just use it like this. This example uses the `Simple\Evaluator` (see [php-json-rpc-simple](https://github.com/datto/php-json-rpc-simple)) as underlying mapping mechanism:
```php
$authenticator = new Authenticator(array(
new BasicAuthHandler(),
// ...
));
$server = new Server(new Auth\Evaluator(new Simple\Evaluator(), $authenticator));
echo $server->reply('...');
```
Requirements
------------
* PHP >= 5.3
Installation
------------
```javascript
"require": {
"datto/json-rpc-auth": "~4.0"
}
```
License
-------
This package is released under an open-source license: [LGPL-3.0](https://www.gnu.org/licenses/lgpl-3.0.html).
Author
------
Written by Chad Kosie and [Philipp C. Heckel](https://github.com/binwiederhier).