PHP code example of gamez / mite-api-authentication

1. Go to this page and download the library: Download gamez/mite-api-authentication 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/ */

    

gamez / mite-api-authentication example snippets


use Gamez\Mite\MiteAuthenticationMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

$stack = HandlerStack::create();
$stack->push(new MiteAuthenticationMiddleware('accountname', 'apikey'));

$client = new Client(['handler' => $stack]);

use Gamez\Mite\MiteAuthentication;
use Http\Discovery\HttpClientDiscovery;
use Http\Message\Authentication\BasicAuth;
use Http\Client\Common\PluginClient;
use Http\Client\Common\Plugin\AuthenticationPlugin;

$authentication = new MiteAuthentication('accountname', 'apikey');
$authenticationPlugin = new AuthenticationPlugin($authentication);

$client = new PluginClient(
    HttpClientDiscovery::find(),
    [$authenticationPlugin]
);

use Gamez\Mite\MiteRequestAuthenticator;

$authenticator = new MiteRequestAuthenticator('accountname', 'apikey');
$request = ...; // an implementation of Psr\Http\Message\RequestInterface

$authenticatedRequest = $authenticator->authenticate($request);