crtl/slim-auth-middleware
Composer 安装命令:
composer require crtl/slim-auth-middleware
包简介
Simple Middleware for custom authorization.
README 文档
README
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 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();
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 class CustomAuthorization extends \Crtl\AuthorizationMiddleware\AbstractAuthorization{ protected function isAuthorized(): bool { /* @var \Psr\Http\Message\ResponseInterface $response */ $response = $this->response; /* @var \Psr\Http\Message\RequestInterface $request */ $request = $this->request; /* check if authorized */ return true; } }
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-10-23