PHP code example of ridibooks / internal-auth

1. Go to this page and download the library: Download ridibooks/internal-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ridibooks / internal-auth example snippets


use Ridibooks\InternalAuth\Authorization\Generator\JwtGenerator;

$key_config = [
    '... issuer service name  ...' => [
        'kid' => '... key id ...',
        'key' => '... rsa private key ...',
    ]
];

$jwt_generator = new JwtGenerator($key_config);
$token = $jwt_generator->generate(
    '... issuer service name  ...',
    '... audience service name ...'
)

use Ridibooks\InternalAuth\Authorization\Validator\JwtValidator;
use Ridibooks\InternalAuth\Authorizer;

$internal_auth_token = '...';

try {
    $jwk_url = $this->configs['jwk_url'];
    $validator = new JwtValidator($jwk_url);

    $authorizer = new Authorizer($validator);
    $authorizer->authorize($internal_auth_token, [InterService.Account]);
} catch (AuthorizationException $e) {
	// handle exception
}

use Ridibooks\InternalAuth\Authorization\Validator\JwtValidator;
use Ridibooks\InternalAuth\Authorizer;

$internal_auth_token = '...';

try {
    $jwk_url = $this->configs['jwk_url'];
    $cache_item_pool = new FilesystemAdapter(); // [psr-6](https://www.php-fig.org/psr/psr-6/) Implementation Adaptor
    $validator = new JwtValidator($jwk_url, $cache_item_pool);

    $authorizer = new Authorizer($validator);
    $authorizer->authorize($internal_auth_token, [InterService.Account]);
} catch (AuthorizationException $e) {
	// handle exception
}