*
@param PagSeguroCredentials $credentials
@param PagSeguroAuthorizationRequest $authorizationRequest
@param bool $onlyAuthorizationCode
@return bool|string
@throws Exception
975913
public static function createAuthorizationRequest(
        PagSeguroCredentials $credentials,
        PagSeguroAuthorizationRequest $authorizationRequest,
        $onlyAuthorizationCode
    ) {

        LogPagSeguro::info("PagSeguroAuthorizationService.Register(" . $authorizationRequest->toString() . ") - begin");

        $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);

        try {
            $connection = new PagSeguroHttpConnection();
            $connection->post(
                self::buildAuthorizationUrl($connectionData),
                PagSeguroAuthorizationParser::getData($authorizationRequest),
                $connectionData->getServiceTimeout(),
                $connectionData->getCharset()
            );

            return self::authorizationReturn(
                $connection,
                $authorizationRequest,
                $connectionData,
                $onlyAuthorizationCode
            );

        } catch (PagSeguroServiceException $err) {
            throw $err;
        } catch (Exception $err) {
            LogPagSeguro::error("Exception: " . $err->getMessage());
            throw $err;
        }
    }
688016
public function completeAuthorizationRequest(AuthorizationRequest $authRequest, ResponseInterface $response)
    {
        return $this->enabledGrantTypes[$authRequest->getGrantTypeId()]
            ->completeAuthorizationRequest($authRequest)
            ->generateHttpResponse($response);
    }
636656
public AccessToken obtainAccessTokenByCode(String authorizationCode) throws InvalidCodeException, TokenExpiredException {
        AccessToken token = tp().obtainAccessTokenByAuthzCode(authorizationCode);
        return token;
    }
791703
public function requestAccessToken($callbackUri, $authorizationCode)
    {
        $params = array(
            'client_id' => $this->appId,
            'client_secret' => $this->appSecret,
            'code' => $authorizationCode,
            'grant_type' => 'authorization_code',
            'redirect_uri' => $callbackUri,
            'response_type' => 'code',
            'scope' => $this->scope,
            'strict' => $this->strictChecks,
        );

        $url = sprintf('%s%s', $this->endpoint, $this->paths['access_token']);

        $this->logger->info(sprintf("Requesting AccessToken to '%s'", $url));
        $this->logger->debug(sprintf('Sent params: %s', json_encode($params)));

        $response = $this->browser->submit($url, $params);

        $this->logger->debug(sprintf('Response of AccessToken: %s', $response));

        $content = $response->getContent();
        $response = json_decode($content, true);

        if (null === $response) {
            $this->logger->error('Received non-json response.', array('response' => $content));

            throw new OAuthException('provider', "Response content couldn't be converted to JSON.");
        }

        if (isset($response['error'])) {
            $this->logger->error('The OAuth2 provider responded with an error', array('response' => $response));

            $error = $response['error'];
            $message = $response['message'];

            throw new OAuthException($error, $message);
        }

        $token = $response['access_token'];
        $scope = $response['scope'];

        return array('access_token' => $token, 'scope' => $scope);
    }
131648
public function queryAuth($authorization_code)
    {
        $params = array(
            'component_appid'    => $this->appid,
            'authorization_code' => $authorization_code,
        );

        return $this->http->jsonPost(self::API_QUERY_AUTH, $params);
    }
99411
private void getCredentials(final String code) {
        new AsyncTask<Void, Void, Boolean>() {
            @Override
            protected Boolean doInBackground(Void... params) {
                try {
                    mBootstrapper.getUserCredentials(code);
                    return true;

                } catch (IOException ex) {
                    LOGGER.error("Error getting oauth credentials", ex);
                    setResult(RESULT_CANCELED);
                    finish();

                } catch (CStorageException ex) {
                    LOGGER.error("Error getting oauth credentials", ex);
                    setResult(RESULT_CANCELED);
                    finish();
                }
                // Failure
                return false;
            }

            @Override
            protected void onPostExecute(Boolean result) {
                if(result) {
                    setResult(RESULT_OK);
                } else {
                    setResult(RESULT_CANCELED);
                }
                finish();
            }
        }.execute();
    }
951727
public function authenticate($code)
    {
        // Validate code
        if (!$code || strlen($code) != 6) {
            throw new Exception('Invalid authorization code');
        }

        // Check for required items
        if (!$this->clientId) {
            throw new Exception('Client ID is required');
        }
        if (!$this->clientSecret) {
            throw new Exception('Client secret is required');
        }
        if (!$this->redirectUri) {
            throw new Exception('Redirect URI is required');
        }

        $fields = [
            'client_id'     => $this->clientId,
            'client_secret' => $this->clientSecret,
            'code'          => $code,
            'redirect_uri'  => urlencode($this->redirectUri),
            'grant_type'    => 'authorization_code'
        ];

        $url  = 'https://';
        $url .= $this->level . '.';
        $url .= (!empty($this->environment)) ? $this->environment . '.' : '';
        $url .= self::HOSTNAME . '/' . self::TOKEN;

        $this->http->setUrl($url)
                   ->setPostFields($fields)
                   ->setHeader(['Accept' => 'application/json']);

        $data = json_decode($this->http->execute());

        if (isset($data->access_token)) {
            $this->setAccessToken($data->access_token);
            $this->setOrcid($data->orcid);
        } else {
            // Seems like the response format changes on occasion...not sure what's going on there?
            $error = (isset($data->error_description)) ? $data->error_description : $data->{'error-desc'}->value;

            throw new Exception($error);
        }

        return $this;
    }
301448
public function getAuthorizerAccessToken($appId, $refreshToken)
    {
        $cacheKey = $this->getAuthorizerAccessTokenCacheKey($appId);
        $credential = $this->cache->get($cacheKey);
        if (!$credential || $credential['expireTime'] - time() < 60) {
            $ret = $this->authorizerToken($appId, $refreshToken);
            if ($ret['code'] !== 1) {
                return $ret;
            } else {
                $credential = [
                    'accessToken' => $ret['authorizer_access_token'],
                    'expireTime' => time() + $ret['expires_in'],
                    'refreshToken' => $ret['authorizer_refresh_token'],
                ];
                $this->cache->set($cacheKey, $credential);
            }
        }

        return $credential['accessToken'];
    }
1359145
private function _createAuthorizeOnBillingAgreementRequest ($authorizationAmount, 
            $authorizationReferenceId, $CaptureNow)
    {
        $authorizeOnBillingAgreementRequest = new OffAmazonPaymentsService_Model_AuthorizeOnBillingAgreementRequest();
        $authorizeOnBillingAgreementRequest->setAmazonBillingAgreementId(
                $this->_amazonBillingAgreementId);
        $authorizeOnBillingAgreementRequest->setSellerId($this->_sellerId);
        $authorizeOnBillingAgreementRequest->setAuthorizationReferenceId($authorizationReferenceId);
        $authorizeOnBillingAgreementRequest->setAuthorizationAmount(
                new OffAmazonPaymentsService_Model_Price());
        $authorizeOnBillingAgreementRequest->getAuthorizationAmount()->setAmount(
                $authorizationAmount);
        $authorizeOnBillingAgreementRequest->getAuthorizationAmount()->setCurrencyCode(
                $this->_service->getMerchantValues()
                    ->getCurrency());
        $authorizeOnBillingAgreementRequest->setCaptureNow($CaptureNow);
        return $authorizeOnBillingAgreementRequest;
    }
1043591
public function getAuthorizationCode($code)
    {
        $code = $this->collection('code_table')->findOne(array(
            'authorization_code' => $code
        ));
        return is_null($code) ? false : $code;
    }
1007303
public function getCopyForSubRequest($onlyPersistentArguments = true)
    {
        if (!$onlyPersistentArguments) {
            // create a new request with all data
            $argumentsArray = $this->argumentsAccessor->getData();
            return new SearchRequest(
                $argumentsArray,
                $this->contextPageUid,
                $this->contextSystemLanguageUid,
                $this->contextTypoScriptConfiguration
            );
        }

        $arguments = new ArrayAccessor();
        foreach ($this->persistentArgumentsPaths as $persistentArgumentPath) {
            if ($this->argumentsAccessor->has($persistentArgumentPath)) {
                $arguments->set($persistentArgumentPath, $this->argumentsAccessor->get($persistentArgumentPath));
            }
        }

        return new SearchRequest(
            $arguments->getData(),
            $this->contextPageUid,
            $this->contextSystemLanguageUid,
            $this->contextTypoScriptConfiguration
        );
    }
647915
function isAllowed(/*iAuthResource*/ $resource = null, /*iIdentity*/ $role = null)
    {
        $role = ($role) ?: $this->identity();

        if (!is_object($resource)
            || (!$resource instanceof PermResource || !method_exists($resource, 'getRouteMatch'))
        )
            throw new \Exception('Invalid Resource Type, Can`t Check The Permissions.');

        $return = true;

        $matchedRouteName = $resource->getRouteMatch()->getMatchedRouteName();

        // Access Admin Route Need Authorized User
        if ($matchedRouteName == \yimaAdminor\Module::ADMIN_ROUTE_NAME)
            $return = $return && $role->hasAuthenticated();

        return $return;
    }
660137
public function getAuthorizationCode($code)
    {
        if (isset($this->authorizationCodes[$code])) {
            return $this->authorizationCodes[$code];
        }

        return null;
    }
757414
private function _authorizePaymentAmount ($authorizationAmount, $authorizationReferenceId)
    {
        $response = $this->callStepAndCheckForException('authorizePaymentAmount', 
                array(
                    $authorizationAmount,
                    $authorizationReferenceId
                ));
        
        $this->printResponseToWebpage("printAuthorizeOnBillingAgreementResponse", array(
            $response
        ));
        
        return getAmazonAuthorizationIdFromAuthorizeOnBillingAgreementResponse($response);
    }
1165641
public static function readAuthorization($str_xml)
    {
        // Parser
        $parser = new PagSeguroXmlParser($str_xml);

        return self::buildAuthorization(
            new PagSeguroAuthorization(),
            $parser->getResult('authorization')
        );
    }
148914
public function capture(
        $authorizationCode,
        $buyOrder,
        $captureAmount,
        $commerceCode = null
    ) {
        $capture = new CaptureInput();
        $capture->authorizationCode = $authorizationCode;
        $capture->buyOrder = $buyOrder;
        $capture->captureAmount = $captureAmount;
        $capture->commerceId = $commerceCode ? $commerceCode : SecurityHelper::getCommonName(
            $this->service->getCertificationBag()->getClientCertificate()
        );;

        return $this->service->capture($capture);
    }
1075124
public function fetchAccessToken($authCode, array $params = [])
    {
        $defaultParams = [
            'appid' => $this->clientId,
            'secret' => $this->clientSecret,
            'js_code' => $authCode,
            'grant_type' => 'authorization_code'
        ];

        $request = $this->createRequest()
            ->setMethod('GET')
            ->setUrl($this->tokenUrl)
            ->setData(array_merge($defaultParams, $params));

        $response = $this->sendRequest($request);

        $token = $this->createToken(['params' => $response]);
        $this->userParams = $response;
        $this->setAccessToken($token);

        return $token;
    }