php - MVC frameworks, API layers, and Authentication/Permissions -


i asked question earlier, may have been vague or broad warrant answer. i've since reconsidered approach , question.

i'm working on framework specific application in mind, keeping re-usability @ forefront. key element of framework exposing api layer, json driven remote interaction.

my issue in planning out comes authentication/permissions. if i'm designing mvc style architecture in mind, yet want permit usage via api layer, should authentication/permissions check take place?

the web access layer same api layer, difference being output method (html vs. json), figured common business logic layer 2 make sense. requests normalized data structure, , sent business logic. business logic kicks out result data structure (query results, failure, success, etc.) either fed template engine, or serialized json.

it appears me permissions check needs performed in common business logic layer, there better place incorporate mvc/api framework?

i don't know else elaborate @ moment, feel free ask more details , i'll provide come them.

how plan on allowing users access api?

here's how role-based authorization:

  • each controller typically has multiple actions (methods) accessible frontend, e.g.
    • function action_get($id)
    • function action_delete($id)
  • each controller has class property specifies roles required each action, e.g.
    protected $access = array(     'get' => null,  // can access; line isnt necessary though     'delete' => array('admin')  // admins can access )
  • a before() method fired before executing action. authorization check based on $access list.
  • each action responsible determining output, e.g.
public function action_get($id) {       // business logic... build data structure       # ...        if (request::is_ajax()) {           // output json       }       else {           // output html       }   }

that system expanded allow api calls. either expand on output portion of method, detecting if api request, or create action api call. if choose latter method , wish keep code dry, move business logic data structure helper method (e.g. protected function _get()). there may better ways of providing access , handling api well.. depends on how want allow access , how flexible/dry want make it.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -