src/GrantType/AuthorizationCodeGrantTypeHandler.php
private function checkCode(
        Request $request,
        $clientId
    ) {
        // code is required and must in valid format.
        $code = $request->request->get('code');
        $errors = $this->validator->validate($code, [
            new \Symfony\Component\Validator\Constraints\NotBlank(),
            new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Code(),
        ]);
        if (count($errors) > 0) {
            throw new InvalidRequestException([
                'error_description' => 'The request includes an invalid parameter value.',
            ]);
        }

        // Check code with database record.
        $codeManager = $this->modelManagerFactory->getModelManager('code');
        $result = $codeManager->readModelOneBy([
            'code' => $code,
        ]);
        if ($result === null || $result->getClientId() !== $clientId) {
            throw new InvalidGrantException([
                'error_description' => 'The provided authorization grant is invalid.',
            ]);
        } elseif ($result->getExpires() < new \DateTime()) {
            throw new InvalidGrantException([
                'error_description' => 'The provided authorization grant is expired.',
            ]);
        }

        return [$result->getUsername(), $result->getScope()];
    }
private function checkCode(
        Request $request,
        $clientId
    ) {
        // code is required and must in valid format.
        $code = $request->request->get('code');
        $errors = $this->validator->validate($code, [
            new \Symfony\Component\Validator\Constraints\NotBlank(),
            new \AuthBucket\OAuth2\Symfony\Component\Validator\Constraints\Code(),
        ]);
        if (count($errors) > 0) {
            throw new InvalidRequestException([
                'error_description' => 'The request includes an invalid parameter value.',
            ]);
        }

        // Check code with database record.
        $codeManager = $this->modelManagerFactory->getModelManager('code');
        $result = $codeManager->readModelOneBy([
            'code' => $code,
        ]);
        if ($result === null || $result->getClientId() !== $clientId) {
            throw new InvalidGrantException([
                'error_description' => 'The provided authorization grant is invalid.',
            ]);
        } elseif ($result->getExpires() < new \DateTime()) {
            throw new InvalidGrantException([
                'error_description' => 'The provided authorization grant is expired.',
            ]);
        }

        return [$result->getUsername(), $result->getScope()];
    }
private function checkCode ( Request $ request , $ clientId ) { // code is required and must in valid format. $ code = $ request -> request -> get ( 'code' ) ; $ errors = $ this -> validator -> validate ( $ code , [ new \ Symfony \ Component \ Validator \ Constraints \ NotBlank ( ) , new \ AuthBucket \ OAuth2 \ Symfony \ Component \ Validator \ Constraints \ Code ( ) , ] ) ; if ( count ( $ errors ) > 0 ) { throw new InvalidRequestException ( [ 'error_description' => 'The request includes an invalid parameter value.' , ] ) ; } // Check code with database record. $ codeManager = $ this -> modelManagerFactory -> getModelManager ( 'code' ) ; $ result = $ codeManager -> readModelOneBy ( [ 'code' => $ code , ] ) ; if ( $ result === null || $ result -> getClientId ( ) !== $ clientId ) { throw new InvalidGrantException ( [ 'error_description' => 'The provided authorization grant is invalid.' , ] ) ; } elseif ( $ result -> getExpires ( ) < new \ DateTime ( ) ) { throw new InvalidGrantException ( [ 'error_description' => 'The provided authorization grant is expired.' , ] ) ; } return [ $ result -> getUsername ( ) , $ result -> getScope ( ) ] ; }
Fetch code from POST.

@param Request $request  Incoming request object
@param string  $clientId Corresponding client_id that code should belongs to

@return array A list with stored username and scope, originally grant in authorize endpoint

@throw InvalidRequestException If code in invalid format.
@throw InvalidGrantException If code provided is no longer valid.
Fetch code from POST .