/**
  * @throws AuthenticationException
  * @param array $credentials
  * @return Identity
  */
 public function authenticate(array $credentials)
 {
     list($code, $state) = $credentials;
     $session = $this->session->getSection(AuthPresenterTrait::$OAUTH_SESSION);
     if (empty($session->state) || $session->state !== $state) {
         throw new AuthenticationException('Invalid state.');
     }
     try {
         $accessToken = $this->provider->getAccessToken('authorization_code', ['code' => $code]);
         /* @var $data AngelcamUser */
         $data = $this->provider->getResourceOwner($accessToken);
     } catch (\Exception $e) {
         $invalidToken = $e instanceof ClientException && $e->getResponse()->getStatusCode() === 401;
         throw new AuthenticationException($invalidToken ? 'Invalid token' : 'Authentication failed', 0, $e);
     }
     return new Identity($data->getId(), $data, $accessToken);
 }
 protected function storeOAuthState()
 {
     $this->getSession(self::$OAUTH_SESSION)->state = $this->angelcamProvider->getState();
 }