/**
  * Function is static. It's doing extraUser registration.
  * return Own user id
  * 
  * @param ExternalUser object $extUser
  * @param ExternalAuth $extObj
  * 
  * @return integer|boolean
  */
 public static function registerExtUser(ExternalUser $extUser, ExternalAuth $extAuth)
 {
     $um = Reg::get(ConfigManager::getConfig("Users", "Users")->Objects->UserManagement);
     $tepmOwnUser = new User();
     $randomPassword = generateRandomString(12);
     $username = static::findFreeRandomUsername($extAuth->getName());
     $userId = $um->createUser($username, $randomPassword, $tepmOwnUser);
     if ($userId !== false) {
         $extAuth->addToExtMap($userId, $extUser);
     }
     return $userId;
 }
 /**
  * Ignore this, MailChimp is not using refresh tokens. However, this is working code we used for SalesForce
  *
  * @param $params
  *   Provide custom parameters.
  *
  * @return
  *   The URL for the login flow.
  */
 public function refreshToken()
 {
     $auth = ExternalAuth::load(ExternalSystem::SALESFORCE, true);
     $orig_data = $auth->getInfo();
     $session = $this->getVariable('_session');
     if (!$orig_data['oauth']['refresh_token']) {
         throw new OAuth2Exception(array('Invalid refresh token, please re-authorize your account'));
     }
     $params = array('grant_type' => 'refresh_token', 'client_id' => $this->getVariable('client_id'), 'client_secret' => $this->getVariable('client_secret'), 'refresh_token' => $orig_data['oauth']['refresh_token']);
     $this->setVariable('token_as_header', false);
     $data = $this->makeRequest($this->getVariable('access_token_uri'), 'POST', $params);
     $this->setVariable('token_as_header', true);
     $data = json_decode($data, true);
     if (!$data['access_token']) {
         throw new OAuth2Exception(array('Invalid Session, please re-authorize your account'));
     }
     $data['refresh_token'] = $orig_data['oauth']['refresh_token'];
     $session = $this->getSessionObject($data);
     $orig_data['oauth'] = $session;
     $auth->setInfo($orig_data);
     $auth->username = null;
     $auth->password = null;
     $auth->api_key = null;
     $auth->save();
     $this->setSession($session, false);
 }
 public function __construct(Registry $Registry, $gfcSiteId)
 {
     if (!extension_loaded('curl')) {
         throw new \Lampcms\Exception('Cannot use this class because php extension "curl" is not loaded');
     }
     parent::__construct($Registry);
     $this->gfcSiteId = $gfcSiteId;
     $this->getGfcCookieVal();
 }