PHPackages                             germania-kg/redirect-unauthorized - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. germania-kg/redirect-unauthorized

ActiveLibrary[Security](/categories/security)

germania-kg/redirect-unauthorized
=================================

1.1.1(8y ago)063MITPHP

Since Dec 12Pushed 8y ago2 watchersCompare

[ Source](https://github.com/GermaniaKG/RedirectUnauthorized)[ Packagist](https://packagist.org/packages/germania-kg/redirect-unauthorized)[ RSS](/packages/germania-kg-redirect-unauthorized/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (5)Versions (7)Used By (0)

Germania · RedirectUnauthorized
===============================

[](#germania--redirectunauthorized)

**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

[](#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
------------

[](#installation)

```
$ composer require germania-kg/redirect-unauthorized
```

Customization
-------------

[](#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
-----

[](#usage)

```
