/** * Exchange the request token and secret for an access token and secret, to sign API calls. * * @return array array('oauth_token' => the access token, 'oauth_token_secret' => the access secret) */ public function accessToken($oauth_verifier = false, $oauth_token = false) { $parameters = []; // 1.0a if ($oauth_verifier) { $parameters['oauth_verifier'] = $oauth_verifier; } $request = $this->signedRequest($this->access_token_url, $this->access_token_method, $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; }
/** * builds the Authorization: header */ 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 = []; foreach ($this->parameters as $k => $v) { if (substr($k, 0, 5) != "oauth") { continue; } if (is_array($v)) { throw new OAuthExceptionPHP('Arrays not supported in headers'); } $out .= $first ? ' ' : ','; $out .= OAuthUtil::urlencode_rfc3986($k) . '="' . OAuthUtil::urlencode_rfc3986($v) . '"'; $first = false; } return $out; }