Exemplo n.º 1
0
 public function __construct()
 {
     $numargs = func_num_args();
     $this->token = new TPTokenData();
     if ($numargs == 1 && func_get_arg(0) instanceof TPTokenData) {
         $this->token = func_get_arg(0);
         return;
     }
     if ($numargs == 1 && func_get_arg(0) instanceof TPRID) {
         $rid = TPRID::parse(func_get_arg(0));
         $this->token->addField(TPTokenData::RID, $rid->toString());
         return;
     }
     if ($numargs == 2) {
         $rid = TPRID::parse(func_get_arg(0));
         $expiration = func_get_arg(1);
         $this->token->addField(TPTokenData::RID, $rid->toString());
         $this->token->addField(TPTokenData::EX, $expiration != null ? TPTokenData::convertToEpochSeconds($expiration) : 0);
         return;
     }
     if ($numargs == 3) {
         $rid = TPRID::parse(func_get_arg(0));
         $expiration = func_get_arg(1);
         $eex = func_get_arg(2);
         $this->token->addField(TPTokenData::RID, $rid->toString());
         $this->token->addField(TPTokenData::EX, $expiration != null ? TPTokenData::convertToEpochSeconds($expiration) : 0);
         $this->token->addField(TPTokenData::EARLY_EX, $eex != null ? TPTokenData::convertToEpochSeconds($eex) : 0);
         return;
     }
 }
Exemplo n.º 2
0
 /**
  *
  * @param <String> $rid String RID
  */
 public function getAccessTokenByRID($rid)
 {
     $rid = TPRID::parse($rid);
     if ($this->contains($rid)) {
         return $this->tokens[$rid->getID()];
     }
     return null;
 }
Exemplo n.º 3
0
 public function parseAccessTokens($raw)
 {
     if ($raw == null || $raw == "") {
         return null;
     }
     $json = (array) json_decode($raw);
     $accessTokenList = array();
     if (!is_array($json)) {
         $tokenMap = $json;
         $ridHash = TPRIDHash::parse($tokenMap[TPTokenData::RID]);
         $token = $this->parseAccessToken($ridHash, $tokenMap);
         $accessToken = new TPAccessToken($token);
         $accessTokenList[] = $accessToken;
     } else {
         try {
             //1.0 tokens cannot be parsed in this version
             if (isset($json['tokens'])) {
                 return new TPAccessTokenList($accessTokenList);
             }
             foreach ($json as $tokenMap) {
                 $tokenMap = (array) $tokenMap;
                 if (isset($tokenMap['rid']) == false) {
                     continue;
                 }
                 if (array_key_exists('rid', $tokenMap) && $tokenMap['rid'] == '') {
                     continue;
                 }
                 $rid = TPRID::parse($tokenMap[TPTokenData::RID]);
                 $token = $this->parseAccessToken($rid->toString(), $tokenMap);
                 $accessToken = new TPAccessToken($token);
                 $accessTokenList[] = $accessToken;
             }
         } catch (Exception $e) {
             return new TPAccessTokenList($accessTokenList);
         }
     }
     return new TPAccessTokenList($accessTokenList);
 }