AuthBucket\OAuth2\ResponseType\AbstractResponseTypeHandler::checkScope PHP Method

checkScope() protected method

protected checkScope ( Request $request, $clientId, $username, $redirectUri, $state )
$request Symfony\Component\HttpFoundation\Request
    protected function checkScope(Request $request, $clientId, $username, $redirectUri, $state)
    {
        // scope may not exists.
        $scope = $request->query->get('scope');
        if (empty($scope)) {
            return;
        }
        // scope must be in valid format.
        $errors = $this->validator->validate($scope, [new NotBlank(), new Scope()]);
        if (count($errors) > 0) {
            throw new InvalidRequestException(['redirect_uri' => $redirectUri, 'state' => $state, 'error_description' => 'The request includes an invalid parameter value.']);
        }
        $scope = preg_split('/\\s+/', $scope);
        // Compare if given scope within all supported scopes.
        $scopeSupported = [];
        $scopeManager = $this->modelManagerFactory->getModelManager('scope');
        $result = $scopeManager->readModelAll();
        if ($result !== null) {
            foreach ($result as $row) {
                $scopeSupported[] = $row->getScope();
            }
        }
        if (array_intersect($scope, $scopeSupported) !== $scope) {
            throw new InvalidScopeException(['redirect_uri' => $redirectUri, 'state' => $state, 'error_description' => 'The requested scope is unknown.']);
        }
        // Compare if given scope within all authorized scopes.
        $scopeAuthorized = [];
        $authorizeManager = $this->modelManagerFactory->getModelManager('authorize');
        $result = $authorizeManager->readModelOneBy(['clientId' => $clientId, 'username' => $username]);
        if ($result !== null) {
            $scopeAuthorized = $result->getScope();
        }
        if (array_intersect($scope, $scopeAuthorized) !== $scope) {
            throw new InvalidScopeException(['redirect_uri' => $redirectUri, 'state' => $state, 'error_description' => 'The requested scope is invalid.']);
        }
        return $scope;
    }