PHPackages                             daydiff/yii2-auth-chain - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. daydiff/yii2-auth-chain

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

daydiff/yii2-auth-chain
=======================

Yii2 authorization chain

v1.0.0(9y ago)06MITPHP &gt;=5.4.0

Since Jul 27Compare

[ Source](https://github.com/daydiff/yii2-auth-chain)[ Packagist](https://packagist.org/packages/daydiff/yii2-auth-chain)[ Docs](https://github.com/daydiff/yii2-auth-chain)[ RSS](/packages/daydiff-yii2-auth-chain/feed)WikiDiscussions Synced 2d ago

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

Yii2 extension implementing authorization chain
===============================================

[](#yii2-extension-implementing-authorization-chain)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1f79eb85b4ed5b55a527c68f07479cc20fd3d9561b8ace060549b7f327f2ba58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646179646966662f796969322d617574682d636861696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/daydiff/yii2-auth-chain)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/6ac5062d0e744116d311370a85f0ce4a82fdfe0c98b9e29b33b7bfe5a8dc5653/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f646179646966662f796969322d617574682d636861696e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/daydiff/yii2-auth-chain)

What is it for?
---------------

[](#what-is-it-for)

For applications with hierarhical access roles system.

Any examples? It's not clear
----------------------------

[](#any-examples-its-not-clear)

You have an application - API. You have two roles here:

- admin - they can watch statistics and edit clients;
- client - they can see own statistics and set settings.

You need to allow admins to authorize as clients without knowing their passwords just from admin interface. And you need to allow admins to get back to their own privilegis/account without re-logining. And of course you need to log all changes made by admins as clients properly, so you always knew who actually made some changes.

Install
-------

[](#install)

```
$ composer require daydiff/yii2-auth-chain
```

Usage
-----

[](#usage)

Register application component:

```
'components' => [
    'authChain' => [
        'class' => 'Daydiff\AuthChain\Service'
    ],
]
```

You need to declare a member class implementing \\Daydiff\\AuthChain\\MemberInterface

```
//Member.php
namespace app\foo\bar;

class Member implements \Daydiff\AuthChain\MemberInterface
{
    private $id;
    private $login;

    /**
     * @inheritdoc
     */
    function getId()
    {
        return $this->id;
    }

    /**
     * @inheritdoc
     */
    function getLogin()
    {
        return $this->login;
    }

    /**
     * @inheritdoc
     */
    function setId($id)
    {
        $this->id = $id;
        return $this;
    }

    /**
     * @inheritdoc
     */
    function setLogin($login)
    {
        $this->login = $login;
        return $this;
    }
}
```

In your action used to authorize as client:

```
public function actionAuthAs($id)
{
    $user = \Yii::$app->getIdentity()->getUser();
    $member = new app\foo\bar\Member();
    $member->setId($user->id)
        ->setLogin($user->login);
    \Yii::$app->authChain->push($member);

    //and then you do authorization work
}
```

When you need to know who user actually is:

```
$member = \Yii::$app->authChain->last();
$realUserId = $member->getId();
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3626d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2212845?v=4)[Aleksandr Tabakov](/maintainers/Daydiff)[@daydiff](https://github.com/daydiff)

---

Top Contributors

[![daydiff](https://avatars.githubusercontent.com/u/2212845?v=4)](https://github.com/daydiff "daydiff (20 commits)")

---

Tags

authorizationsessionyii2extensionChaindaydiff

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/daydiff-yii2-auth-chain/health.svg)

```
[![Health](https://phpackages.com/badges/daydiff-yii2-auth-chain/health.svg)](https://phpackages.com/packages/daydiff-yii2-auth-chain)
```

###  Alternatives

[kakadu-dev/yii2-jwt-auth

Extension provide JWT auth for Yii2

105.8k](/packages/kakadu-dev-yii2-jwt-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
