Example #1
0
 protected function execute(InputInterface $in, OutputInterface $out)
 {
     $sessionFile = $in->getOption('session');
     if (NULL !== $sessionFile) {
         // @todo Catch JsonValidationException and show errors.
         $fileUtility = $this->getFileUtility();
         $sessionFile = $fileUtility->expandPath($sessionFile);
         $this->session = JsonSessionFile::read($sessionFile);
     } else {
         $this->session = new Session();
     }
     $defaults = $this->getDefaults();
     $consumer = $this->session->getConsumerCredentials();
     if (!$consumer) {
         $consumer = new ConsumerCredentials();
         $this->session->setConsumerCredentials($consumer);
     }
     $consumerKey = $in->getOption('consumer-key');
     if ($consumerKey) {
         $consumer->setKey($consumerKey);
     } elseif ('' == $consumer->getKey() && isset($defaults['consumer-key'])) {
         $consumer->setKey($defaults['consumer-key']);
     }
     $consumerSecret = $in->getOption('consumer-secret');
     if ($consumerSecret) {
         $consumer->setSecret($consumerSecret);
     } else {
         if ('' == $consumer->getSecret() && isset($defaults['consumer-secret'])) {
             $consumer->setSecret($defaults['consumer-secret']);
         }
     }
 }
Example #2
0
 /**
  * @param string $path
  * @return \CultuurNet\Auth\Session
  */
 public static function read($path)
 {
     if (!file_exists($path)) {
         return new Session();
     }
     $json = file_get_contents($path);
     if (!$json) {
         return new Session();
     }
     $data = json_decode($json);
     // @todo Throw an exception if unable to parse.
     if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
     }
     self::validateSchema($data, $path);
     $session = new Session();
     if (isset($data->baseUrls)) {
         foreach (get_object_vars($data->baseUrls) as $api => $baseUrl) {
             $session->setBaseUrl($api, $baseUrl);
         }
     }
     if (isset($data->consumer)) {
         $consumer = new ConsumerCredentials();
         $consumer->setKey($data->consumer->key);
         $consumer->setSecret($data->consumer->secret);
         $session->setConsumerCredentials($consumer);
     }
     if (isset($data->user)) {
         $tokenCredentials = new TokenCredentials($data->user->token, $data->user->secret);
         $user = new User($data->user->id, $tokenCredentials);
         $session->setUser($user);
     }
     return $session;
 }