<commit_before><?php

namespace LoginCidadao\OpenIDBundle\Controller;

use FOS\OAuthServerBundle\Event\OAuthEvent;
use LoginCidadao\OAuthBundle\Entity\Organization;
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata;
use LoginCidadao\OpenIDBundle\Manager\ClientManager;
use LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\Request;
use OAuth2\ServerBundle\Controller\AuthorizeController as BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use LoginCidadao\OAuthBundle\Model\OrganizationInterface;
use LoginCidadao\OAuthBundle\Model\ClientInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;

class AuthorizeController extends BaseController
{

    /**
     * @Route("/openid/connect/authorize", name="_authorize_handle")
     * @Method({"POST"})
     */
    public function handleAuthorizeAction()
    {
        $request = $this->getRequest();
        $scope = $request->request->get('scope');
        $is_authorized = $request->request->has('rejected') === false || $request->request->has('accepted')
            === true;
        $request->request->set('scope', implode(' ', $scope));

        $server = $this->get('oauth2.server');
        $client = $this->getClient($request);

        $response = $this->handleAuthorize($server, $is_authorized);

        $event = new OAuthEvent($this->getUser(), $client, $is_authorized);
        $this->get('event_dispatcher')
            ->dispatch(OAuthEvent::POST_AUTHORIZATION_PROCESS, $event);

        return $response;
    }

    /**
     * @Template()
     */
    public function authorizeAction(
        $client_id,
        $scope,
        $response_type,
        $redirect_uri,
        $state = null,
        $nonce = null
    ) {
        $client = $this->getClient($client_id);

        $scope = explode(' ', $scope);
        if (array_search('public_profile', $scope) === false) {
            $scope[] = 'public_profile';
        }

        $scopeManager = $this->getScopeManager();
        $scopes = array_map(
            function ($value) {
                return $value->getScope();
            },
            $scopeManager->findScopesByScopes($scope)
        );

        $warnUntrusted = $this->shouldWarnUntrusted($client);
        $metadata = $this->getMetadata($client);
        $organization = $this->getOrganization($metadata);

        $qs = compact(
            'client_id',
            'scope',
            'response_type',
            'redirect_uri',
            'state',
            'nonce'
        );

        return compact('qs', 'scopes', 'client', 'warnUntrusted', 'metadata', 'organization');
    }

    /**
     * @Route("/openid/connect/authorize", name="_authorize_validate")
     * @Method({"GET"})
     * @Template("OAuth2ServerBundle:Authorize:authorize.html.twig")
     */
    public function validateAuthorizeAction()
    {
        $request = $this->getRequest();
        $client = $this->getClient($request);

        if ($client instanceof \FOS\OAuthServerBundle\Model\ClientInterface) {
            $event = $this->get('event_dispatcher')->dispatch(
                OAuthEvent::PRE_AUTHORIZATION_PROCESS,
                new OAuthEvent($this->getUser(), $client)
            );

            $server = $this->get('oauth2.server');
            if ($event->isAuthorizedClient()) {
                return $this->handleAuthorize(
                    $server,
                    $event->isAuthorizedClient()
                );
            }
        }

        return parent::validateAuthorizeAction();
    }

    /**
     * @return \OAuth2\ServerBundle\Manager\ScopeManager<commit_msg>not ignoring prompt parameter. PROCERGS#672<commit_after><?php

namespace LoginCidadao\OpenIDBundle\Controller;

use FOS\OAuthServerBundle\Event\OAuthEvent;
use LoginCidadao\OAuthBundle\Entity\Organization;
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata;
use LoginCidadao\OpenIDBundle\Manager\ClientManager;
use LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\Request;
use OAuth2\ServerBundle\Controller\AuthorizeController as BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use LoginCidadao\OAuthBundle\Model\OrganizationInterface;
use LoginCidadao\OAuthBundle\Model\ClientInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;

class AuthorizeController extends BaseController
{

    /**
     * @Route("/openid/connect/authorize", name="_authorize_handle")
     * @Method({"POST"})
     */
    public function handleAuthorizeAction()
    {
        $request = $this->getRequest();
        $scope = $request->request->get('scope');
        $is_authorized = $request->request->has('rejected') === false || $request->request->has('accepted')
            === true;
        $request->request->set('scope', implode(' ', $scope));

        $server = $this->get('oauth2.server');
        $client = $this->getClient($request);

        $response = $this->handleAuthorize($server, $is_authorized);

        $event = new OAuthEvent($this->getUser(), $client, $is_authorized);
        $this->get('event_dispatcher')
            ->dispatch(OAuthEvent::POST_AUTHORIZATION_PROCESS, $event);

        return $response;
    }

    /**
     * @Template()
     */
    public function authorizeAction(
        $client_id,
        $scope,
        $response_type,
        $redirect_uri,
        $state = null,
        $nonce = null
    ) {
        $client = $this->getClient($client_id);

        $scope = explode(' ', $scope);
        if (array_search('public_profile', $scope) === false) {
            $scope[] = 'public_profile';
        }

        $scopeManager = $this->getScopeManager();
        $scopes = array_map(
            function ($value) {
                return $value->getScope();
            },
            $scopeManager->findScopesByScopes($scope)
        );

        $warnUntrusted = $this->shouldWarnUntrusted($client);
        $metadata = $this->getMetadata($client);
        $organization = $this->getOrganization($metadata);

        $qs = compact(
            'client_id',
            'scope',
            'response_type',
            'redirect_uri',
            'state',
            'nonce'
        );

        return compact('qs', 'scopes', 'client', 'warnUntrusted', 'metadata', 'organization');
    }

    /**
     * @Route("/openid/connect/authorize", name="_authorize_validate")
     * @Method({"GET"})
     * @Template("OAuth2ServerBundle:Authorize:authorize.html.twig")
     */
    public function validateAuthorizeAction()
    {
        $request = $this->getRequest();
        $client = $this->getClient($request);

        if ($client instanceof \FOS\OAuthServerBundle\Model\ClientInterface) {
            $event = $this->get('event_dispatcher')->dispatch(
                OAuthEvent::PRE_AUTHORIZATION_PROCESS,
                new OAuthEvent($this->getUser(), $client)
            );

            $shouldPrompt = $request->get('prompt', null) == 'consent';

            $server = $this->get('oauth2.server');
            if ($event->isAuthorizedClient() && !$shouldPrompt) {
                return $this->handleAuthorize(
                    $server,
                    $event->isAuthorizedClient()
                );
            }
        }

        return parent::validateAuthorizeAction();
    }

    /**
     * @return \OAuth2\ServerBundle\Manager\ScopeManager
{'fraction_non_alphanumeric': 0.13932844461597838, 'fraction_numerical': 0.001672455937218577, 'mean_word_length': 2.687855787476281, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '137937', 'n_tokens_mistral': 2237, 'n_tokens_neox': 2187, 'n_words': 324}