# Authentication 2.0 Plugins

**URL:** https://discourse.cakephp.org/t/authentication-2-0-plugins/11044
**Category:** Plugins
**Created:** [March 12, 2023, 3:11pm UTC](https://discourse.cakephp.org/t/authentication-2-0-plugins/11044 "2023-03-12T15:11:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![devtun](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@devtun](https://discourse.cakephp.org/u/devtun)
#### Post date: [March 12, 2023, 3:11pm UTC](https://discourse.cakephp.org/t/authentication-2-0-plugins/11044/1 "2023-03-12T15:11:57Z")

</div>

In Auth component we use

Public function beforeFilter(Envent $event){  
parent::beforeFilter(event);  
$this-\>Auth-\>deny(actions);

}

To deny access to specific action in a controller.

How do i achieve this same operation using Authentication 2.0 plugin?

---

<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: [March 12, 2023, 7:48pm UTC](https://discourse.cakephp.org/t/authentication-2-0-plugins/11044/2 "2023-03-12T19:48:05Z")

</div>

By default the new authentication plugins deny access to all actions if you are not logged in. See [here](https://book.cakephp.org/authentication/2/en/authentication-component.html#authentication-component)

So you would have to specifically allow actions to be accessed as not logged in users (which we recommend to not unintentionally publish stuff you don’t want to)

```auto
public function beforeFilter(\Cake\Event\EventInterface $event)
{
    parent::beforeFilter($event);
    $this->Authentication->allowUnauthenticated(['login', 'index', 'view']);
}

```

But if you want to invert that behavior so that everything is allowed as not logged in users besides specific actions you need to [set this config](https://book.cakephp.org/authentication/2/en/authentication-component.html#configure-automatic-identity-checks)

Also please watch my workshop talking about the new auth plugins.

[![](https://img.youtube.com/vi/EgN_iEVjQIA/maxresdefault.jpg "WORKSHOP - Authentication & Authorization by Kevin Pfeifer") ](https://www.youtube.com/watch?v=EgN_iEVjQIA)

---

<div class="post-metadata">

### Author: ![devtun](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@devtun](https://discourse.cakephp.org/u/devtun)
#### Post date: [March 13, 2023, 12:38pm UTC](https://discourse.cakephp.org/t/authentication-2-0-plugins/11044/3 "2023-03-13T12:38:42Z")

</div>

KevinPfeifer  
I have watched your video many times but you did not mention this type of case study.

I have about 25 methods in a controller, I want to allow all methods except only one (1) of then. How do i get it done?

In AuthComponent we have $this-\>Auth-\>deny([‘register’]); What can we use in place of this deny action in Authentication plugin.

Thanks

---

<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: [March 13, 2023, 3:10pm UTC](https://discourse.cakephp.org/t/authentication-2-0-plugins/11044/4 "2023-03-13T15:10:52Z")

</div>

With the help of the others in the core team I got something for you

```auto
    public function beforeFilter(EventInterface $event)
    {
        $action = $this->getRequest()->getParam('action');
        if ($action !== 'register') {
            $this->Authentication->allowUnauthenticated([$action]);
        }
    }

```

---

<div class="post-metadata">

### Author: ![devtun](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@devtun](https://discourse.cakephp.org/u/devtun)
#### Post date: [March 15, 2023, 3:56am UTC](https://discourse.cakephp.org/t/authentication-2-0-plugins/11044/5 "2023-03-15T03:56:50Z")

</div>

Very helpful, thanks
