本文整理汇总了PHP中OAuthServer::checkAccess方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthServer::checkAccess方法的具体用法?PHP OAuthServer::checkAccess怎么用?PHP OAuthServer::checkAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthServer
的用法示例。
在下文中一共展示了OAuthServer::checkAccess方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelRequest
/**
* @param GetResponseEvent $event
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* @return bool
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (strpos($event->getRequest()->attributes->get('_controller'), 'Api\\Resource') !== false) {
header('Access-Control-Allow-Origin: *');
$controller = explode('::', $event->getRequest()->attributes->get('_controller'));
$reflection = new \ReflectionMethod($controller[0], $controller[1]);
$scopeAnnotation = $this->reader->getMethodAnnotation($reflection, 'Etu\\Core\\ApiBundle\\Framework\\Annotation\\Scope');
if ($scopeAnnotation) {
$requiredScope = $scopeAnnotation->value;
} else {
$requiredScope = null;
}
if (!$requiredScope) {
$requiredScope = 'public';
}
$request = $event->getRequest();
$token = $request->query->get('access_token');
$access = $this->server->checkAccess($token, $requiredScope);
if (!$access->isGranted()) {
$event->setResponse($this->formatter->format($event->getRequest(), ['error' => $access->getError(), 'error_message' => $access->getErrorMessage()], 403));
} else {
$event->getRequest()->attributes->set('_oauth_token', $access->getToken());
}
}
}