1. Go to this page and download the library: Download sympla/mesa-gold-bar 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/ */
sympla / mesa-gold-bar example snippets
ympla\Auth\OAuth2RemoteAuthentication;
$authenticator = new OAuth2RemoteAuthentication(
new GuzzleHttp\Client,
'https://example.com/api/whoami'
);
//Gets the user from the request object
$request = Request::createFromGlobals(); // hydrates the psr-7 request object
$user = $authenticator->getUserFromRequest($request);
// Or, alternatively, gets the user from the token directly:
$token = explode(" ", $_SERVER['HTTP_AUTHORIZATION'])[1];
$user = $authenticator->getUserFromToken($token);
var_dump($user); // dumps information fetched from the endpoint server about the user.
#middleware.php
$app->add(new \Sympla\Auth\Middleware\SlimMiddleware(
new \GuzzleHttp\Client,
$app->getContainer(),
[
'protected' => ['/^\/admin\//'], //This is a regex for the protected URIs
'authentication_server' => getenv('USER_INFO_ENDPOINT') //This is where the middleware
//should try to fetch the user info from
]
));