Resolves grant type for given request

@param IRequest $request

@return IGrantType|IAuthorizationGrantType
@throws \OAuth2\Exception\UnsupportedGrantTypeException
432375
public function resolve(IRequest $request)
    {
        foreach ($this->grantTypes as $grantType) {
            if ($grantType->match($request)) {
                return $grantType;
            }
        }

        throw new UnsupportedGrantTypeException;
    }
650947
public static function getClass(Request $Request)
    {
        foreach (static::$_registry as $registered) {
            if (in_array($Request->ext, $registered['extensions'])) {
                return $registered['resolve']($Request);
            }
        }

        throw new ErrorException("The following extension is not handled: {$Request->ext}");
    }
8912
public function identitiesAction(Request $request)
    {
        $objectType = $request->get('objectType');
        $objectId = $request->get('objectId', null);

        $objectIdentityResolver = $this->get('phlexible_access_control.object_identity_resolver');
        $objectIdentity = $objectIdentityResolver->resolve($objectType, $objectId);

        if (!$objectIdentity) {
            throw new \InvalidArgumentException("Unsupported object type $objectType");
        }

        $accessManager = $this->get('phlexible_access_control.access_manager');

        $acl = $accessManager->findAcl($objectIdentity);

        return new JsonResponse(array('identities' => $this->createIdentities($acl)));
    }
564623
public function types(Request $request, array $types)
    {
        foreach ($types as $type) {
            $field = new $type($request);
            $this->type($field->singularLabel(), $type::$model, $field->fields($request));
        }

        return $this;
    }
30258
protected function authorize(Request $request)
    {
        $isAuthorized = true;

        // if authorization is required check it as well
        if (($authorizationClosure = $this->getAuthorizationClosure()) !== null) {
            $isAuthorized = $authorizationClosure($request);
        }

        return $isAuthorized;
    }
1030526
public function resolveIdsToNames(Request $request)
    {

        // Resolve the Esi client library from the IoC
        $eseye = app('esi-client')->get();

        // Grab the ids from the request for processing
        collect(explode(',', $request->ids))
            ->map(function ($id) {

                // Convert them all to integers
                return (int) $id;
            })
            ->unique()
            ->filter(function ($id) {

                // Filter out ids that are System items
                // see: https://gist.github.com/a-tal/5ff5199fdbeb745b77cb633b7f4400bb
                if ($id <= 10000)
                    return false;

                // Next, filter the ids we have in the cache, setting
                // the appropriate response values as we go along.
                if ($cached_entry = cache($this->prefix . $id)) {

                    $this->response[$id] = $cached_entry;

                    // Remove this as a valid id, we already have the value we want.
                    return false;
                }

                // We don't have this id in the cache. Return it
                // so that we can update it later.
                return true;
            })
            ->pipe(function ($collection) {
                return $collection->when($collection->isNotEmpty(), function ($ids) {
                    return $this->resolveFactionIDs($ids);
                });
            })
            ->pipe(function ($collection) {
                return $collection->when($collection->isNotEmpty(), function ($ids) {
                    return $this->resolveInternalUniverseIDs($ids);
                });
            })
            ->pipe(function ($collection) {
                return $collection->when($collection->isNotEmpty(), function ($ids) {
                    return $this->resolveInternalCharacterIDs($ids);
                });
            })
            ->pipe(function ($collection) {
                return $collection->when($collection->isNotEmpty(), function ($ids) {
                    return $this->resolveInternalCorporationIDs($ids);
                });
            })
            ->chunk(1000)
            ->each(function ($chunk) use ($eseye) {

                // quick break if no more IDs must be resolve by ESI
                if ($chunk->isEmpty())
                    return;

                $this->resolveIDsfromESI($chunk, $eseye);

            });

        return response()->json($this->response);
    }
1180399
protected function authenticateViaBearerToken($request)
    {
        // First, we will convert the Symfony request to a PSR-7 implementation which will
        // be compatible with the base OAuth2 library. The Symfony bridge can perform a
        // conversion for us to a Zend Diactoros implementation of the PSR-7 request.
        $psr = (new DiactorosFactory)->createRequest($request);

        try {
            $psr = $this->server->validateAuthenticatedRequest($psr);

            // If the access token is valid we will retrieve the user according to the user ID
            // associated with the token. We will use the provider implementation which may
            // be used to retrieve users from Eloquent. Next, we'll be ready to continue.
            $user = $this->provider->retrieveById(
                $psr->getAttribute('oauth_user_id')
            );

            if (! $user) {
                return;
            }

            // Next, we will assign a token instance to this user which the developers may use
            // to determine if the token has a given scope, etc. This will be useful during
            // authorization such as within the developer's Laravel model policy classes.
            $token = $this->tokens->find(
                $psr->getAttribute('oauth_access_token_id')
            );

            $clientId = $psr->getAttribute('oauth_client_id');

            // Finally, we will verify if the client that issued this token is still valid and
            // its tokens may still be used. If not, we will bail out since we don't want a
            // user to be able to send access tokens for deleted or revoked applications.
            if ($this->clients->revoked($clientId)) {
                return;
            }

            return $token ? $user->withAccessToken($token) : null;
        } catch (OAuthServerException $e) {
            return Container::getInstance()->make(
                ExceptionHandler::class
            )->report($e);
        }
    }
1125514
private function handleGetRequest(Rest\RestRequest $request)
    {
        if (true === $request->hasIdentifier()) {
            if (false === $request->isRelationship() && false === $request->hasFilters()) {
                return $this->findRecord($request->getEntityType(), $request->getIdentifier());
            }
            if (true === $request->isRelationshipRetrieve()) {
                return $this->findRelationship($request->getEntityType(), $request->getIdentifier(), $request->getRelationshipFieldKey());
            }
            throw AdapterException::badRequest('No GET handler found.');
        } else {
            if (true === $request->isAutocomplete()) {
                // @todo Eventually add pagination (limit/skip)
                return $this->autocomplete($request->getEntityType(), $request->getAutocompleteKey(), $request->getAutocompleteValue());
            }
            if (true === $request->isQuery()) {
                return $this->findQuery($request->getEntityType(), $request->getQueryCriteria(), $request->getFieldset(), $request->getSorting(), $request->getPagination(), $request->getInclusions());
            }
            return $this->findAll($request->getEntityType(), [], $request->getFieldset(), $request->getSorting(), $request->getPagination(), $request->getInclusions());
        }
        throw AdapterException::badRequest('No GET handler found.');
    }
366944
public function authenticate(IRequest $request)
    {
        foreach ($this->clientAuthenticationMethods as $clientAuthenticationMethod) {
            if ($clientAuthenticationMethod->match($request)) {
                return $clientAuthenticationMethod->authenticate($request);
            }
        }

        throw new InvalidClientException('Invalid client authentication method.');
    }
198023
public function isOAuthAuthenticated(ServerRequestInterface $request)
    {
        $queryParams = $request->getQueryParams();
        $code = $queryParams[GoogleClient::KEY_CODE] ?? null;
        $state = $queryParams[GoogleClient::KEY_STATE] ?? null;

        $this->logger->debug(
            json_encode(
                [
                    'Incoming authorization code: ' . $code,
                    'Incoming state: ' . $state,
                    'Redirect uri: ' . $this->getConfig('redirectUri'),
                ]
            )
        );

        if ($this->getSession($request)->get(GoogleClient::KEY_STATE) != $state) {
            $this->logger->debug("Invalid incoming state");

            return false;
        }

        if (!$this->googleClient->authenticateWithAuthCode($code)) {
            $this->logger->debug("Authentication with authorization code failed");

            return false;
        }

        return true;
    }
5402
public function receiveSignedAuthnRequestFrom(Request $request)
    {
        if (!$this->entityRepository) {
            throw new LogicException(
                'Could not receive AuthnRequest from HTTP Request: a ServiceProviderRepository must be configured'
            );
        }

        if (!$request->isMethod(Request::METHOD_GET)) {
            throw new BadRequestHttpException(sprintf(
                'Could not receive AuthnRequest from HTTP Request: expected a GET method, got %s',
                $request->getMethod()
            ));
        }

        $requestUri = $request->getRequestUri();
        if (strpos($requestUri, '?') === false) {
            throw new BadRequestHttpException(
                'Could not receive AuthnRequest from HTTP Request: expected query parameters, none found'
            );
        }

        list(, $rawQueryString) = explode('?', $requestUri);
        $query = ReceivedAuthnRequestQueryString::parse($rawQueryString);

        if (!$query->isSigned()) {
            throw new UnsignedRequestException('The SAMLRequest is expected to be signed but it was not');
        }

        if (!$this->signatureVerifier->verifySignatureAlgorithmSupported($query)) {
            throw new UnsupportedSignatureException(
                $query->getSignatureAlgorithm()
            );
        }

        $authnRequest = ReceivedAuthnRequest::from($query->getDecodedSamlRequest());

        $currentUri = $this->getFullRequestUri($request);
        if (!$authnRequest->getDestination() === $currentUri) {
            throw new BadRequestHttpException(sprintf(
                'Actual Destination "%s" does not match the AuthnRequest Destination "%s"',
                $currentUri,
                $authnRequest->getDestination()
            ));
        }

        if (!$this->entityRepository->hasServiceProvider($authnRequest->getServiceProvider())) {
            throw new UnknownServiceProviderException($authnRequest->getServiceProvider());
        }

        $serviceProvider = $this->entityRepository->getServiceProvider($authnRequest->getServiceProvider());

        // Note: verifyIsSignedBy throws an Exception when the signature does not match.
        if (!$this->signatureVerifier->verifyIsSignedBy($query, $serviceProvider)) {
            throw new SignatureValidationFailedException(
                'Validation of the signature in the AuthnRequest failed'
            );
        }

        return $authnRequest;
    }
405740
private function _allowOrigin($request) {
        $allowOrigin = Configure::read('Cors.AllowOrigin');
        $origin = $request->getHeader('Origin');

        if ($allowOrigin === true || $allowOrigin === '*') {
            return $origin;
        }

        if (is_array($allowOrigin)) {
            $origin = (array) $origin;

            foreach ($origin as $o) {
                if (in_array($o, $allowOrigin)) {
                    return $origin;
                }
            }

            return '';
        }

        return (string)$allowOrigin;
    }
1245744
public function negotiate(Request $request)
    {
        if ([] === $this->supportedMediaTypes) {
            return null;
        }

        if (!$request->hasHeader('Content-Type')) {
            return null;
        }

        return $this->compareAgainstSupportedMediaTypes($request->getHeaderLine('Content-Type'));
    }
604389
public function unsealRequest(
        RequestInterface $request,
        SealingSecretKey $secretKey
    ): RequestInterface {
        $body = Base64UrlSafe::decode((string) $request->getBody());
        $unsealed = Simple::unseal(
            $body,
            $secretKey
        );
        return $request->withBody($this->adapter->stringToStream($unsealed));
    }
478314
public function issueToken(IRequest $request)
    {
        if (!$request->isMethod('post')) {
            throw new InvalidHttpMethodException;
        }

        $grantType = $this->grantTypeResolver->resolve($request);

        return $grantType->grant($request);
    }
252679
protected function repeaterHasSubTypes(Request $request)
    {
        if (!$resourceId = $this->getResourceId($request)) {
            return false;
        }

        if (!$model = $this->model()->whereId($resourceId)->first()) {
            return false;
        }

        return method_exists($model->type, 'types');
    }
1170821
public function setAllowedGrantTypes($allowedGrantTypes)
    {
        foreach ($allowedGrantTypes as $allowedGrantType) {
            if (!in_array($allowedGrantType, $this->availableGrantTypes)) {
                throw new \Exception('Unknown grant type ' . $allowedGrantType);
            }
        }
        $this->allowedGrantTypes = $allowedGrantTypes;
    }