문제

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