Happyr\LinkedIn\Authenticator::getCode PHP Method

getCode() protected method

Get the authorization code from the query parameters, if it exists, and otherwise return null to signal no authorization code was discovered.
protected getCode ( ) : string | null
return string | null The authorization code, or null if the authorization code not exists.
    protected function getCode()
    {
        $storage = $this->getStorage();
        if (!GlobalVariableGetter::has('code')) {
            return;
        }
        if ($storage->get('code') === GlobalVariableGetter::get('code')) {
            //we have already validated this code
            return;
        }
        // if stored state does not exists
        if (null === ($state = $storage->get('state'))) {
            throw new LinkedInException('Could not find a stored CSRF state token.');
        }
        // if state not exists in the request
        if (!GlobalVariableGetter::has('state')) {
            throw new LinkedInException('Could not find a CSRF state token in the request.');
        }
        // if state exists in session and in request and if they are not equal
        if ($state !== GlobalVariableGetter::get('state')) {
            throw new LinkedInException('The CSRF state token from the request does not match the stored token.');
        }
        // CSRF state has done its job, so clear it
        $storage->clear('state');
        return GlobalVariableGetter::get('code');
    }