Frage

I am creating APIs in zend framework. I want to authorize each API call. I am passing some information in header which is used for authorization purpose.

Currently I am authorizing API calls in module.php but the problem I faced in this is I am not able to return proper response code. If authorization fails, it should return 403.

Is there any other place than Module.php where I can authorize all the API calls ?

War es hilfreich?

Lösung 3

I have done this in Module.php as it's called before any of the controllers.

Advantage of doing this in module.php

1)You don't have to do this in all the controllers

2)We can directly return error response from the Module.php if call is not authorized.

Andere Tipps

I'm using https://github.com/php-loep/oauth2-server (oauth2)

I do authorizations in controller.

If you want to send HTTP response the better place would be controller or view, since you had mentioned API you could return null or some other error codes(responses) to alert the models/modules that are going to use your API

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top