You are here

public function OAuthRequest::to_header in OAuth 1.0 7.3

Same name and namespace in other branches
  1. 6.3 lib/OAuth.php \OAuthRequest::to_header()
  2. 6 OAuth.php \OAuthRequest::to_header()

builds the Authorization: header

File

lib/OAuth.php, line 447
OAuth 1.0 server and client library.

Class

OAuthRequest

Code

public function to_header($realm = null) {
  $first = true;
  if ($realm) {
    $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($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 .= OAuthUtil::urlencode_rfc3986($k) . '="' . OAuthUtil::urlencode_rfc3986($v) . '"';
    $first = false;
  }
  return $out;
}