コード例 #1
0
 /**
  * Get the session key between an application and the API server. 
  *
  * @param unknown_type $api_key
  * @param unknown_type $secret_key
  * @param RingsideSocialSession $socialSession
  * @return string session key for the API container
  */
 public static function getApiSessionKey($api_key, $secret_key, RingsideSocialSession $socialSession)
 {
     $uid = $socialSession->getUserId();
     $sessionKey = $socialSession->getApiSessionKey($api_key);
     if ($sessionKey != null) {
         // Validate Session Key is still valid.
         $apiClient = new RingsideApiClientsRest($api_key, $secret_key, $sessionKey);
         $apiClient->setNetworkKey($socialSession->getNetwork());
         try {
             $apiClient->users_getLoggedInUser();
         } catch (Exception $e) {
             //            error_log( "Session expired? " . $e->getMessage() ) ;
             //            error_log($e->getTraceAsString());
             $sessionKey = null;
             $socialSession->unsetApiSessionKey($api_key);
         }
     }
     if ($sessionKey == null && $uid != null) {
         // Need to simulate being app and auth, approve, get... which of course
         // TODO we need to re-think once we are working.
         // TODO catch some exceptions.
         try {
             // Configure where we get the URL for the REST SERVER from.
             $apiClient = new RingsideApiClientsRest($api_key, $secret_key, null, null, RingsideSocialConfig::$apiKey);
             // Once the client is authenticated with a session, the network key will be associated via the session
             $apiClient->setNetworkKey($socialSession->getNetwork());
             $auth_token = $apiClient->auth_createToken($socialSession->getExpiry() == null ? true : false);
             $result = $apiClient->auth_approveToken($uid);
             $result = $apiClient->auth_getSession($auth_token);
             if (!empty($apiClient->session_key)) {
                 $sessionKey = trim($apiClient->session_key);
                 $socialSession->addApiSessionKey($api_key, $sessionKey);
             }
         } catch (Exception $exception) {
             error_log("Error creating session key " . $exception);
         }
     }
     return $sessionKey;
 }
コード例 #2
0
 public function getNetworkSession($apiKey, $secretKey, $session, $trust_key)
 {
     $secret = '';
     if (!isset($secretKey) || strlen($secretKey) == 0) {
         $props = $this->getAppPropertiesByApiKey($apiKey);
         $secret = $props['secret_key'];
     }
     $url = $this->getAuthUrl($trust_key);
     $ringsideClient = new RingsideApiClientsRest($apiKey, $secret, $session, $url);
     // Make sure the user is logged in and get the UID
     $userid = $ringsideClient->users_getLoggedInUser();
     if (!isset($userid) || strlen($userid) == 0) {
         throw new Exception("User is not logged in, invalid session: {$session} or api key: {$apiKey}");
     }
     $network_session = new RingsideSocialSession();
     $network_session->setUserId($userid);
     $network_session->setLoggedIn(true);
     return $network_session;
 }