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');
}