Cakephp3 handle authorization as a plugin

I’ve been working on cakephp3 for a while now. I’ve always used Cakephp’s Auth component for authorization and authentication purpose.

I follow the very conventional procedure every time, like loading the component, adding isAuthorized function in controllers and defining allowMethods etc.

But now what I want is to develop my own plugin for this purpose, just using Cake’s Auth component. So that i can reuse the plugin in all my future projects, also i want it to be like plug and play. Like You enable it, add few settings and your User management is done.

I know that how migrations work so I can add users table via migration every time. (Just an idea)

The thing I don’t get right now is how to make everything separate from the core app? Like everything is done via plugin and nothing is added to every controller of the app.

Hope I’m clear about what I want to achieve. Any solutions to my problem would save my day.

I know there is a whole list of third party Auth plugins. But I want to develop my own so i just need the idea of how things work.

It’s a been a while since I’ve done active CakePHP development work, and I’m not overly familiar with CakePHP 3, but it sounds like you should make yourself familiar with CakePHP Events, particularly the Controller and Component events.

However, if you’re isAuthorized and defining allowMethods as your primary method of Authorization, you may need to switch it up so something a little more convention based or database driven.

Perhaps look at the source code for a few of those plugins to see how they achieve their goals (Auth Plugin and documented example), especially if there is one that comes close to what you want to do. However, closing the gap between what they provide, and what you want to achieve may have to be your own work.