Example #1
0
 /**
  * Este método será utilizado para decodificar token's.
  *
  * @param string $token Este é o Token a ser decodificado.
  * @return stdClass Estão são os dados retornados pelo Token.
  */
 public static function decode($token)
 {
     $token = (array) json_decode(self::arrange(base64_decode($token)));
     if (!Ao_Signature::validate($token, KA_APP_KEY_SECRET)) {
         return null;
     }
     if (!is_numeric($token['time']) || $token['time'] > time()) {
         return null;
     }
     if ($token['host'] != filter_input(INPUT_SERVER, 'HTTP_HOST')) {
         return null;
     }
     return (object) $token;
 }
Example #2
0
 public function getTokenAccess($key, $secret, $authorization, $verifier)
 {
     # define destino da requisição
     $this->http->setUri($this->host . '/oauth/token');
     # prepara parâmetros da requisição
     $data = ['oauth_consumer_key' => $key, 'oauth_timestamp' => time(), 'oauth_nonce' => '', 'oauth_token' => $authorization, 'oauth_verifier' => $verifier, 'oauth_signature_method' => 'HMAC-SHA512'];
     $data['oauth_signature'] = Ao_Signature::get($data, $secret);
     # monta requisição
     $this->http->setMethod('POST')->setParameterPost($data);
     # faz requisição
     try {
         $body = $this->http->request()->getBody();
     } catch (Exception $e) {
         throw new Exception('<b>Falha inesperada</b> ao tentar solicitar o Token de Acesso.');
     }
     # converte "json"
     $token = json_decode($body);
     if (empty($token)) {
         throw new Exception($body);
     }
     # retorna "Token de Acesso"
     return $token->oauth_token;
 }