.. include:: ../Includes.txt .. _access_checkaccess: ============ Restricting Access with a custom method ============ How to implement your own method for checking access rights to your endpoint --------- In most cases using the :ref:`@Api\\Access(...)` annotation will be sufficient to restrict the access to your endpoint to certain frontend-users or user groups. In case you need to implement your own logic for checking access rights, you can simply define a ``checkAccess()``-method in the class of your endpoint. This will override the default ``checkAccess()``-method from ``\Nng\Nnrestapi\Api\AbstractApi``. The ``checkAccess()`` method must return ``TRUE``, if the user is allowed to access the endpoint. If it returns ``FALSE``, the script will automatically be aborted and the Api will return a ``HTTP 403 Forbidden`` header. **Here is an example:** .. code-block:: php 'welcome!']; } } The above example can be reached with a ``GET`` request to: .. code-block:: php https://www.mysite.com/api/test/example Example: Restricting access to certain IP-adresses -------- In this example, we will use the ``checkAccess()`` method to check, if the user has a certain IP. The script will only allow access to the methods in this class, if the ``$remoteAddr`` matches one of the patterns defined in ``$allowedIpList``: .. code-block:: php ` you can always call the ``parent::checkAccess()`` method in your custom ``checkAccess()`` method. This will process the login in ``\Nng\Nnrestapi\Api\AbstractApi::checkAccess()`` that handles restrictions made in the annotations. .. code-block:: php