Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crtl/slim-auth-middleware
Basic Authorization Middleware Library
https://github.com/crtl/slim-auth-middleware
Last synced: 4 days ago
JSON representation
Basic Authorization Middleware Library
- Host: GitHub
- URL: https://github.com/crtl/slim-auth-middleware
- Owner: crtl
- Created: 2018-10-23T09:31:14.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-09T15:06:48.000Z (over 5 years ago)
- Last Synced: 2024-11-06T00:51:59.247Z (11 days ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Slim Authorization Middleware
This package provides a basic middleware to implement authorization of any type.
## Installation
```
composer require crtl/slim-auth-middleware
```## Usage
The package already comes with a prebuild implementation for HTTP-Basic Authroziation.
```php
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();
```If the request is authorized the app will call the next middleware. Otherwise `Crtl\AuthorizationMiddleware\AbstractAuthorization::getErrorResponse` will be called.
To implement a custom authorization just extend `Crtl\AuthorizationMiddleware\AbstractAuthorization` and implement the
`protected isAuthorized() : bool` method.```php
response;
/* @var \Psr\Http\Message\RequestInterface $request */
$request = $this->request;
/* check if authorized */
return true;
}
}```