# Cakedc/auth & Cakedc/users : what to do?

**URL:** <https://discourse.cakephp.org/t/cakedc-auth-cakedc-users-what-to-do/4221>\
**Category:** Need Help\
**Created:** [April 24, 2018, 1:50pm UTC](https://discourse.cakephp.org/t/cakedc-auth-cakedc-users-what-to-do/4221 "2018-04-24T13:50:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmebis](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jmebis](https://discourse.cakephp.org/u/jmebis)\
**Post date:** [April 24, 2018, 1:50pm UTC](https://discourse.cakephp.org/t/cakedc-auth-cakedc-users-what-to-do/4221/1 "2018-04-24T13:50:52Z")

</div>

Hello

I want to use the cakedc/users pluging for managing the users and cakedc/auth for RBAC.  
I have read the blogs on [www.cakedc.com](http://www.cakedc.com) but it’s confusing for me.

1. Do I need the install both plugins or only the cakedc/users plugin?
2. I’m trying the ‘owner’ permission but I receive this error:  
Class ‘CakeDC\Users\Auth\Rules\Owner’ not found  
and when I write this in my appcontroller  
$this-\>loadComponent(‘Auth’, [  
‘authorize’ =\> [‘CakeDC/Auth.SimpleRbac’],  
‘loginRedirect’ =\> [  
‘controller’ =\> ‘Articles’,  
‘action’ =\> ‘index’  
],  
‘logoutRedirect’ =\> [  
‘controller’ =\> ‘Pages’,  
‘action’ =\> ‘display’,  
‘home’  
]  
]);  
$this-\>loadComponent(‘CakeDC/Users.UsersAuth’);  
I do receive this error:  
The “Auth” alias has already been loaded with the following config: …

Can you put me on the road?  
Thank you!

cakephp: 3  
cakedc/users: 7.0.0  
cakedc/auth: 2.0.3

---

<div class="post-metadata">

**Author:** ![steinkel](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/steinkel/32/56_2.png) [@steinkel](https://discourse.cakephp.org/u/steinkel)\
**Post date:** [April 24, 2018, 2:00pm UTC](https://discourse.cakephp.org/t/cakedc-auth-cakedc-users-what-to-do/4221/2 "2018-04-24T14:00:57Z")

</div>

1. If you install cakedc/users you’ll get cakedc/auth as it’s a dependency of the Users Plugin
2. Please paste here the code in your permissions.php file, here’s a correct usage example [https://github.com/CakeDC/auth/blob/master/Docs/Documentation/Rbac.md#permission-rules](https://github.com/CakeDC/auth/blob/master/Docs/Documentation/Rbac.md#permission-rules)

About AuthComponent, keep in mind UsersAuthComponent will load and configure AuthComponent internally, so you are getting Auth loaded twice. Please check this link to understand how to configure it [https://github.com/CakeDC/users/blob/master/Docs/Documentation/Configuration.md#default-authenticate-and-authorize-objects-used](https://github.com/CakeDC/users/blob/master/Docs/Documentation/Configuration.md#default-authenticate-and-authorize-objects-used) or you can disable Auth configuration from Users, and using your own using the configuration key `Users.auth` (set it to false).

---

<div class="post-metadata">

**Author:** ![jmebis](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jmebis](https://discourse.cakephp.org/u/jmebis)\
**Post date:** [April 24, 2018, 2:03pm UTC](https://discourse.cakephp.org/t/cakedc-auth-cakedc-users-what-to-do/4221/3 "2018-04-24T14:03:10Z")

</div>

Thank you for your quick respons.  
I will try this.

---

<div class="post-metadata">

**Author:** ![jmebis](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jmebis](https://discourse.cakephp.org/u/jmebis)\
**Post date:** [April 27, 2018, 11:53am UTC](https://discourse.cakephp.org/t/cakedc-auth-cakedc-users-what-to-do/4221/4 "2018-04-27T11:53:28Z")

</div>

Ok, I no longer get errors but the Owner() rule is not working.

In the bootstrap file I only load the cakedc/users plugin  
`Plugin::load('CakeDC/Users', ['bootstrap' => true, 'routes' => true]);`

In the AppController  
public function initialize()  
{  
parent::initialize();

```
        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');
        $this->loadComponent('CakeDC/Users.UsersAuth');
        parent::initialize();
    }

```

And permissions file:  
return [  
‘Users.SimpleRbac.permissions’ =\> [  
//admin role allowed to all the things  
[  
‘role’ =\> ‘admin’,  
‘prefix’ =\> ‘_’,  
‘extension’ =\> '_’,  
‘plugin’ =\> ‘_’,  
‘controller’ =\> '_’,  
‘action’ =\> ‘_’,  
],  
//specific actions allowed for the all roles in Users plugin  
[  
‘role’ =\> '_’,  
‘plugin’ =\> ‘CakeDC/Users’,  
‘controller’ =\> ‘Users’,  
‘action’ =\> [‘profile’, ‘logout’, ‘linkSocial’, ‘callbackLinkSocial’],  
],  
[  
‘role’ =\> ‘\*’,  
‘plugin’ =\> ‘CakeDC/Users’,  
‘controller’ =\> ‘Users’,  
‘action’ =\> ‘resetGoogleAuthenticator’,  
‘allowed’ =\> function (array $user, $role, \Cake\Http\ServerRequest $request) {  
$userId = \Cake\Utility\Hash::get($request-\>getAttribute(‘params’), ‘pass.0’);  
if (!empty($userId) && !empty($user)) {  
return $userId === $user[‘id’];  
}

```
                return false;
            }
        ],
        //all roles allowed to Pages/display
        [
            'role' => '*',
            //'plugin' => null,
            'controller' => 'Pages',
            'action' => 'display',
        ],
      [
            'role' => 'user',
            'controller' => 'Articles',
            'action' => ['index','view'],
        ],
      [
            'role' => 'user',
            'controller' => 'Users',
            'action' => ['index','view'],
        ],
         [
            'role' => '*',
            'controller' => 'Articles',
            'action' => ['edit', 'delete'],
            'allowed' => new \CakeDC\Auth\Rbac\Rules\Owner() //will pick by default the post id from the first pass param
            ],
    ]
];

```

Is there something I still do wrong?
