AuthBucket\OAuth2\GrantType\AuthorizationCodeGrantTypeHandler::checkCode PHP Method

checkCode() private method

Fetch code from POST.
private checkCode ( Request $request, string $clientId ) : array
$request Symfony\Component\HttpFoundation\Request Incoming request object
$clientId string Corresponding client_id that code should belongs to
return array A list with stored username and scope, originally grant in authorize endpoint
    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 NotBlank(), new 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()];
    }
AuthorizationCodeGrantTypeHandler