定制 germania-kg/redirect-unauthorized 二次开发

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

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

germania-kg/redirect-unauthorized

Composer 安装命令:

composer require germania-kg/redirect-unauthorized

包简介

README 文档

README

This package is distilled from legacy code. You certainly do not want this in your production code.

This PSR-style Middleware checks if a Response object status code is 401 Unauthorized and stores the current Request URI in a Aura.Session Segment. If the user is authenticated (i.e. login successful, 204 No Content), he will be redirected to this very URI as his start URL. The redirect status code is 301.

In particular

  1. When the Middleware is executed: If Response object is 401 Unauthorized, store Request URI in session and redirect to login URL.

  2. Call next middleware (or Page controller). A Login controller should on success set the Response object to 204 No Content.

  3. After route, check if Response is 204 No Content and redirect to the URI stored in session.

Installation

$ composer require germania-kg/redirect-unauthorized

Customization

The Response status codes needed are 401 or 204 per default. Create your own extension to use other codes:

class MyRedirector exends Germania\RedirectUnauthorized\Middleware
{
    /**
     * HTTP Status Code for Redirection
     * @var string
     */
    public $redirect_status_code  = 301;
    
    /**
     * HTTP Status Code for "Unauthorized". Usually 401.
     * @var string
     */
    public $auth_required_status_code  = 401;

    /**
     * HTTP Status Code for Responses after successful login. Usually 204.
     * @var string
     */
    public $authorized_status_code = 204;
}

Usage

<?php
use Germania\RedirectUnauthorized\Middleware;

// Aura.Session Segment
$session_factory = new \Aura\Session\SessionFactory;
$session = $session_factory->newInstance($_COOKIE);
$segment = $session->getSegment('Vendor\Package\ClassName');

// Where to redirect unauthorized requests to
$login_url = "/login.html"

// Optional: PSR-3 Logger
$logger = new Monolog

$middleware = new Middleware( $segment, $login_url);
$middleware = new Middleware( $segment, $login_url, $logger);

Slim 3 Example

<?php
use Germania\RedirectUnauthorized\Middleware;

$app = new Slim\App;
$app->add( new Middleware ); 

Development and Testing

Develop using develop branch, using Git Flow.
Currently, no tests are specified.

$ git clone git@github.com:GermaniaKG/RedirectUnauthorized redirect-unauthorized
$ cd redirect-unauthorized
$ cp phpunit.xml.dist phpunit.xml
$ vendor/bin/phpunit

统计信息

  • 总下载量: 63
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固