# Authentication 3 plugin error

**URL:** <https://discourse.cakephp.org/t/authentication-3-plugin-error/11778>\
**Category:** Uncategorized\
**Created:** [January 5, 2024, 11:46am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778 "2024-01-05T11:46:28Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [January 7, 2024, 7:27pm UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/21 "2024-01-07T19:27:49Z")

</div>

[3.0 Migration Guide - 3.x](https://book.cakephp.org/authorization/3/en/3-0-migration-guide.html) has been added

---

<div class="post-metadata">

**Author:** ![shaan007](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/shaan007/32/2765_2.png) [@shaan007](https://discourse.cakephp.org/u/shaan007)\
**Post date:** [January 8, 2024, 6:32am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/22 "2024-01-08T06:32:14Z")

</div>

Thank @KevinPfeifer for upgrade 3.0 Migration so I follow this latest docs but still getting this error… I do not know why applyScope method return null value

 ![Screenshot from 2024-01-08 12-01-13](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/0/045d8fdfe8bb289fbd88d44c11f59d9226cb15a9.png)  
 ![Screenshot from 2024-01-08 12-00-45](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/0/05650cbe35806ac705ac2261f4d9d2bdaed1b1c5.png)

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [January 8, 2024, 6:44am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/23 "2024-01-08T06:44:03Z")

</div>

I thought you already had it working…

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [January 8, 2024, 6:48am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/24 "2024-01-08T06:48:41Z")

</div>

But you are calling that inside the controller, so why not directly use the AuthorizationComponent:

```auto
$query = $this->Authorization->applyScope($query);

```

---

<div class="post-metadata">

**Author:** ![shaan007](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/shaan007/32/2765_2.png) [@shaan007](https://discourse.cakephp.org/u/shaan007)\
**Post date:** [January 8, 2024, 6:54am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/25 "2024-01-08T06:54:16Z")

</div>

in UsersController

```auto
$user = $this->request->getAttribute('identity');
$query = $user->applyScope('index', $this->Users->find());

```

in UsersPolicy I have $user-\>getIdentifier() method which get the ID by default from the users table but I want replace ID to refer\_id so therefor i have to define this method into user entity…

```auto
public function getIdentifier(): int
    {
        return $this->refer_id;
    }

```

```auto
/**
     * @inheritDoc
     */
    public function can(string $action, mixed $resource): bool
    {
        return $this->authorization->can($this, $action, $resource);
    }

    /**
     * @inheritDoc
     */
    public function canResult(string $action, mixed $resource): ResultInterface
    {
        return $this->authorization->canResult($this, $action, $resource);
    }

    /**
     * @inheritDoc
     */
    public function applyScope(string $action, mixed $resource, mixed ...$optionalArgs): mixed
    {

        $scope = $this->authorization->applyScope($this, $action, $resource, ...$optionalArgs);
        dd($scope);
    }

    /**
     * @inheritDoc
     */
    public function getOriginalData(): \ArrayAccess|array
    {
        return $this;
    }

    /**
     * Setter to be used by the middleware.
     */
    public function setAuthorization(AuthorizationServiceInterface $service)
    {
        $this->authorization = $service;

        return $this;
    }

    /**
     * Authentication\IdentityInterface method
     *
     * @return string
     */
    public function getIdentifier(): int
    {
        return $this->refer_id;
    }

```

---

<div class="post-metadata">

**Author:** ![shaan007](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/shaan007/32/2765_2.png) [@shaan007](https://discourse.cakephp.org/u/shaan007)\
**Post date:** [January 8, 2024, 7:10am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/26 "2024-01-08T07:10:25Z")

</div>

$this-\>authorization this is null

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [January 8, 2024, 7:28am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/27 "2024-01-08T07:28:23Z")

</div>

> [@shaan007](#):
>
> ```auto
> 'identityDecorator' => function ($auth, $user) {
> return $user->setAuthorization($auth);
> }
> 
> ```

which it shouldn’t because of this code in your middleware

---

<div class="post-metadata">

**Author:** ![shaan007](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/shaan007/32/2765_2.png) [@shaan007](https://discourse.cakephp.org/u/shaan007)\
**Post date:** [January 8, 2024, 7:31am UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/28 "2024-01-08T07:31:35Z")

</div>

already set added that decorated into middleware @KevinPfeifer

 ![Screenshot from 2024-01-08 13-04-27](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/e/e8c1b2f127d2f34ce9b68fc8bbcb1f1ff8075dd6.png)

---

<div class="post-metadata">

**Author:** ![shaan007](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/shaan007/32/2765_2.png) [@shaan007](https://discourse.cakephp.org/u/shaan007)\
**Post date:** [January 8, 2024, 2:48pm UTC](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778/29 "2024-01-08T14:48:20Z")

</div>

😆I don’t know how but my all problems solve now

[Previous page](https://discourse.cakephp.org/t/authentication-3-plugin-error/11778.md?page=1)
