Skip to content

datto/php-json-rpc-auth

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

JSON-RPC Auth Extension

This is an authentication and authorization extension for the php-json-rpc library. It provides the ability to authorize JSON-RPC requests before they reach the endpoint.

Examples

First write an authentication Handler:

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) as underlying mapping mechanism:

$authenticator = new Authenticator(array(
    new BasicAuthHandler(),
    // ...
));

$server = new Server(new Auth\Evaluator(new Simple\Evaluator(), $authenticator));
echo $server->reply('...');

Requirements

  • PHP >= 5.3

Installation

"require": {
  "datto/json-rpc-auth": "~4.0"
}

License

This package is released under an open-source license: LGPL-3.0.

Author

Written by Chad Kosie and Philipp C. Heckel.

About

Authentication & authorization extension for the JSON-RPC library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages