protected function createAuthenticatedToken($gigyaUserId, \GSResponse $accountInfoResponse) { if (null === $this->userProvider) { return new GigyaUserToken($this->providerKey, $gigyaUserId, array()); } $user = $this->userProvider->loadUserByGigyaUserId($gigyaUserId); if ($user == null) { $user = $this->userProvider->createUserWithGigyaAccount($gigyaUserId, $accountInfoResponse->getData()); } else { $this->userProvider->updateUserWithGigyaAccount($user, $accountInfoResponse->getData()); } if ($user instanceof UserInterface) { $this->userChecker->checkPreAuth($user); $this->userChecker->checkPostAuth($user); } else { throw new AuthenticationServiceException('The user provider must return a UserInterface object.'); } return new GigyaUserToken($this->providerKey, $user, $user->getRoles()); }