1. Go to this page and download the library: Download crtl/slim-auth-middleware 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/ */
crtl / slim-auth-middleware example snippets
use Crtl\AuthorizationMiddleware\BasicAuthorization;
$app = new \Slim\App();
$app->add(
new BasicAuthorization([
BasicAuthorization::CONFIG_ENABLE => true,
BasicAuthorization::CONFIG_USER => "secret",
BasicAuthorization::CONFIG_SECRET => "password"
])
);
$app->get("/", function($request, $response) use ($app) {
$body = $response->getBody();
$body->write("Authorized");
return $response->withBody($body),
});
$app->run();