request->getHeader('Authorization'); if (!$auth) { return null; } if ('bearer ' !== strtolower(substr($auth, 0, 7))) { return null; } return substr($auth, 7); } /** * This method sends the needed HTTP header and statuscode (401) to force * authentication. */ public function requireLogin() { $this->response->addHeader('WWW-Authenticate', 'Bearer realm="'.$this->realm.'"'); $this->response->setStatus(401); } }