/** * Determine if we have an authentication failure, and, if so, return a 401 response * * @param MvcAuthEvent $mvcAuthEvent * @return null|ApiProblemResponse */ public function __invoke(MvcAuthEvent $mvcAuthEvent) { if (!$mvcAuthEvent->hasAuthenticationResult()) { return; } $authResult = $mvcAuthEvent->getAuthenticationResult(); if ($authResult->isValid()) { return; } $mvcEvent = $mvcAuthEvent->getMvcEvent(); $response = new ApiProblemResponse(new ApiProblem(401, 'Unauthorized')); $mvcEvent->setResponse($response); return $response; }
/** * Determine if we have an authentication failure, and, if so, return a 401 response * * @param MvcAuthEvent $mvcAuthEvent * @return null|\Zend\Http\Response */ public function __invoke(MvcAuthEvent $mvcAuthEvent) { if (!$mvcAuthEvent->hasAuthenticationResult()) { return; } $authResult = $mvcAuthEvent->getAuthenticationResult(); if ($authResult->isValid()) { return; } $mvcEvent = $mvcAuthEvent->getMvcEvent(); $response = $mvcEvent->getResponse(); if (!$response instanceof HttpResponse) { return $response; } $response->setStatusCode(401); $response->setReasonPhrase('Unauthorized'); return $response; }
public function testGetAuthenticationResult() { $this->mvcAuthEvent->setAuthenticationResult(new Result('success', 'foobar')); $this->assertInstanceOf('Zend\\Authentication\\Result', $this->mvcAuthEvent->getAuthenticationResult()); }