Authentication

To make authenticated requests via http, you will need to set an authorization headers as follows:

Authorization: Bearer {yourtokenhere}

or pass the token as a query string

?token={yourtokenhere}

Callbacks

By default if the authentication fails, the middleware will stop the execution of routes and will immediately return a response of 401 Unauthorized. If you want to add your own handler:

$auth->onUnauthorized(function($authMicro, $app) {$response=$app["response"];$response->setStatusCode(401, 'Unauthorized');$response->setContentType("application/json");// to get the error messages$response->setContent(json_encode([$authMicro->getMessages()[0]]));$response->send();// return false to stop the executionreturnfalse;});

If you want an additional checking on the authentication, like intentionally expiring a token based on the payload issued date, you may do so: