定制 crtl/slim-auth-middleware 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固