AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Controller\DemoController::authorizeAction PHP Method

authorizeAction() public method

public authorizeAction ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function authorizeAction(Request $request)
    {
        // We only handle non-authorized scope here.
        try {
            return $this->get('authbucket_oauth2.oauth2_controller')->authorizeAction($request);
        } catch (InvalidScopeException $exception) {
            $message = unserialize($exception->getMessage());
            if ($message['error_description'] !== 'The requested scope is invalid.') {
                throw $exception;
            }
        }
        // Fetch parameters, which already checked.
        $clientId = $request->query->get('client_id');
        $username = $this->get('security.token_storage')->getToken()->getUser()->getUsername();
        $scope = preg_split('/\\s+/', $request->query->get('scope', ''));
        // Create form.
        $form = $this->createFormBuilder()->getForm();
        $form->handleRequest($request);
        // Save authorized scope if submitted by POST.
        if ($request->isMethod('POST')) {
            $modelManagerFactory = $this->get('authbucket_oauth2.model_manager.factory');
            $authorizeManager = $modelManagerFactory->getModelManager('authorize');
            // Update existing authorization if possible, else create new.
            $authorize = $authorizeManager->readModelOneBy(['clientId' => $clientId, 'username' => $username]);
            if ($authorize === null) {
                $class = $authorizeManager->getClassName();
                $authorize = new $class();
                $authorize->setClientId($clientId)->setUsername($username)->setScope((array) $scope);
                $authorize = $authorizeManager->createModel($authorize);
            } else {
                $authorize->setClientId($clientId)->setUsername($username)->setScope(array_merge((array) $authorize->getScope(), $scope));
                $authorizeManager->updateModel($authorize);
            }
            // Back to this path, with original GET parameters.
            return $this->redirect($request->getRequestUri());
        }
        // Display the form.
        $authorizationRequest = $request->query->all();
        return $this->render('TestBundle:demo:authorize.html.twig', ['client_id' => $clientId, 'username' => $username, 'scopes' => $scope, 'form' => $form->createView(), 'authorization_request' => $authorizationRequest]);
    }