/** * Generates the basic string serialization of a token that a server * would respond to request_token and access_token calls with. * * @return string */ public function toString() { return 'oauth_token=' . Util::urlencodeRfc3986($this->key) . '&oauth_token_secret=' . Util::urlencodeRfc3986($this->secret); }
/** * Builds the Authorization: header. * * @param string $realm Authorization realm. * * @return string * * @throws JacobKiers\OAuth\OAuthException */ public function toHeader($realm = null) { $first = true; if ($realm) { $out = 'Authorization: OAuth realm="' . Util::urlencodeRfc3986($realm) . '"'; $first = false; } else { $out = 'Authorization: OAuth'; } $total = array(); foreach ($this->parameters as $k => $v) { if (substr($k, 0, 5) != 'oauth') { continue; } if (is_array($v)) { throw new OAuthException('Arrays not supported in headers'); } $out .= $first ? ' ' : ','; $out .= Util::urlencodeRfc3986($k) . '="' . Util::urlencodeRfc3986($v) . '"'; $first = false; } return $out; }
/** * Get the signature key, made up of consumer and optionally token shared secrets. * * @param JacobKiers\OAuth\Consumer\ConsumerInterface $consumer * @param JacobKiers\OAuth\Token\TokenInterface $token * * @return string */ public function getSignatureKey(ConsumerInterface $consumer, TokenInterface $token = null) { $key_parts = array($consumer->getSecret(), $token ? $token->getSecret() : ''); $key_parts = Util::urlencodeRfc3986($key_parts); return implode('&', $key_parts); }
public function testTokenString() { $token = new Token('foo', 'bar'); $string = 'oauth_token=' . Util::urlencodeRfc3986('foo') . '&oauth_token_secret=' . Util::urlencodeRfc3986('bar'); $this->assertEquals($string, $token->toString()); }