Skip to content

Commit

Permalink
Finish 57-no-signing-for-app-only-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetx committed Jun 17, 2014
2 parents ccbd4b8 + b90c8c3 commit a877d2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ codebird-php - changelog
+ #61 Return rate limit details with each API call
+ #60 Support uploading multiple media
- #63 Return rate-limiting info only if contained in response
- #57 Don't require consumer key if bearer token is already known

2.4.1 (2013-06-23)
+ #26 Stringify null and boolean parameters
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ If you already have your token, tell Codebird to use it:
```php
\Codebird\Codebird::setBearerToken('YOURBEARERTOKEN');
```

In this case, you don't need to set the consumer key and secret.
For sending an API request with app-only auth, see the ‘Usage examples’ section.


Expand Down
20 changes: 14 additions & 6 deletions src/codebird.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,14 +1058,20 @@ protected function _callApi($httpmethod, $method, $params = array(), $multipart
if (json_encode($params) !== '{}') {
$url_with_params .= '?' . http_build_query($params);
}
$authorization = $this->_sign($httpmethod, $url, $params);
if (! $app_only_auth) {
$authorization = $this->_sign($httpmethod, $url, $params);
}
$ch = curl_init($url_with_params);
} else {
if ($multipart) {
$authorization = $this->_sign($httpmethod, $url, array());
$params = $this->_buildMultipart($method, $params);
if (! $app_only_auth) {
$authorization = $this->_sign($httpmethod, $url, array());
}
$params = $this->_buildMultipart($method, $params);
} else {
$authorization = $this->_sign($httpmethod, $url, $params);
if (! $app_only_auth) {
$authorization = $this->_sign($httpmethod, $url, $params);
}
$params = http_build_query($params);
}
$ch = curl_init($url);
Expand All @@ -1079,8 +1085,10 @@ protected function _callApi($httpmethod, $method, $params = array(), $multipart
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
if ($app_only_auth) {
if (self::$_oauth_consumer_key === null) {
throw new \Exception('To make an app-only auth API request, the consumer key must be set.');
if (self::$_oauth_consumer_key === null
&& self::$_oauth_bearer_token === null
) {
throw new \Exception('To make an app-only auth API request, consumer key or bearer token must be set.');
}
// automatically fetch bearer token, if necessary
if (self::$_oauth_bearer_token === null) {
Expand Down

0 comments on commit a877d2d

Please sign in to comment.