Authentication 3 plugin error

3.0 Migration Guide - 3.x has been added

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


I thought you already had it working…

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

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

in UsersController

$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…

public function getIdentifier(): int
    {
        return $this->refer_id;
    }
/**
     * @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;
    }

$this->authorization this is null

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

already set added that decorated into middleware @KevinPfeifer

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