質問

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 ?

役に立ちましたか?

解決 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.

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top