/** * @param \Cake\Network\Request $request Request to get authentication information from. * @param \Cake\Network\Response $response A response object that can have headers added. * @return bool|\Cake\Network\Response */ public function unauthenticated(Request $request, Response $response) { if ($this->_config['continue']) { return false; } if (isset($this->_exception)) { $response->statusCode($this->_exception->httpStatusCode); //add : to http code for cakephp (header method in Network/Response expects header separated with colon notation) $headers = $this->_exception->getHttpHeaders(); $code = (string) $this->_exception->httpStatusCode; $headers = array_map(function ($header) use($code) { $pos = strpos($header, $code); if ($pos !== false) { return substr($header, 0, $pos + strlen($code)) . ':' . substr($header, $pos + strlen($code) + 1); } return $header; }, $headers); $response->header($headers); $response->body(json_encode(['error' => $this->_exception->errorType, 'message' => $this->_exception->getMessage()])); return $response; } $message = __d('authenticate', 'You are not authenticated.'); throw new BadRequestException($message); }
/** * @param OAuthException $e * @return mixed */ protected function unsupportedResponseType(OAuthException $e) { return Response::make(['errors' => ['status' => '400', 'code' => 'UnsupportedResponseType', 'title' => 'Unsupported Response Type', 'detail' => $e->getMessage()]], 400); }
/** * Get a response object for an OAuthException. * * @param OAuthException $e * * @return Response */ protected function getExceptionResponse(OAuthException $e) { return new Response(json_encode(['error' => $e->errorType, 'message' => $e->getMessage()]), $e->httpStatusCode, $e->getHttpHeaders()); }
public function handle(OAuthException $e, $request) { return $this->adaptors->make($request)->adapt(['error' => $e->errorType, 'error_description' => $e->getMessage()], $e->httpStatusCode, $e->getHttpHeaders()); }