Skip to content

Switch to PSR-17 and remove deprecated code #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,29 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4]
## Requirements

* PHP >= 7.1
* A [HTTP client](https://packagist.org/providers/psr/http-client-implementation)
* A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation)
* (optional) PHPUnit to run tests.
* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation)
* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation)

## Install

Via [Composer](https://getcomposer.org).

### PHP 7.2+:
### PHP 7.1+:

```bash
composer require knplabs/github-api guzzlehttp/guzzle:^7.0.1
composer require knplabs/github-api:^3.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0
```

### PHP 7.1+:
### PHP 7.2+:

```bash
composer require knplabs/github-api php-http/guzzle6-adapter:^2.0.1
composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
```

### Laravel 5.5+:
### Laravel 6+:

```bash
composer require graham-campbell/github guzzlehttp/guzzle:^7.0.1
composer require graham-campbell/github^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
```

We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell).
Expand Down
23 changes: 13 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,33 @@
],
"require": {
"php": "^7.1",
"php-http/client-common": "^2.1",
"php-http/client-common": "^2.2",
"php-http/cache-plugin": "^1.7",
"php-http/discovery": "^1.7",
"php-http/discovery": "^1.9",
"php-http/httplug": "^2.1",
"php-http/multipart-stream-builder": "^1.1",
"psr/cache": "^1.0",
"psr/http-client-implementation": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^8.0",
"php-http/guzzle6-adapter": "^2.0",
"php-http/mock-client": "^1.2",
"guzzlehttp/psr7": "^1.2",
"cache/array-adapter": "^0.4",
"phpstan/phpstan": "^0.12.23"
"cache/array-adapter": "^1.0.1",
"guzzlehttp/psr7": "^1.5.2",
"http-interop/http-factory-guzzle": "^1.0",
"php-http/guzzle6-adapter": "^2.0.1",
"php-http/mock-client": "^1.4",
"phpstan/phpstan": "^0.12.32",
"phpstan/extension-installer": "^1.0.4",
"phpstan/phpstan-deprecation-rules": "^0.12.4",
"phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.0"
},
"autoload": {
"psr-4": { "Github\\": "lib/Github/" }
},
"autoload-dev": {
"psr-4": { "Github\\Tests\\": "test/Github/Tests/"}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
Expand Down
9 changes: 0 additions & 9 deletions doc/rate_limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Get rate limit wrappers from [GitHub Rate Limit API](http://developer.github.com

#### Get All Rate Limits

##### new way
```php
/** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits */
$rateLimits = $client->api('rate_limit')->getResources();
Expand Down Expand Up @@ -61,14 +60,6 @@ array(4) {
}
```


##### deprecated way

```php
/** @var array $rateLimits */
$rateLimits = $client->api('rate_limit')->getRateLimits();
```

#### Get Core Rate Limit

```php
Expand Down
34 changes: 8 additions & 26 deletions doc/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,29 @@ properties on Repositories and some others. Therefore this step is facultative.

### Authenticate

GitHub provides some different ways of authentication. This API implementation implements three of them which are handled by one function:
GitHub provides some different ways of authentication. This API implementation implements three of them which are
handled by one function:

```php
$client->authenticate($usernameOrToken, $password, $method);
```

`$usernameOrToken` is, of course, the username (or in some cases token/client ID, more details you can find below),
and guess what should contain `$password`. The `$method` can contain one of the five allowed values:

#### Deprecated methods
* `Github\Client::AUTH_URL_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
* `Github\Client::AUTH_URL_CLIENT_ID` use `Github\Client::AUTH_CLIENT_ID` instead.
* `Github\Client::AUTH_HTTP_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
* `Github\Client::AUTH_HTTP_PASSWORD` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
and guess what should contain `$password`. The `$method` can contain one of the three allowed values:

#### Supported methods
* `Github\Client::AUTH_CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret
* `Github\Client::AUTH_ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header
* `Github\Client::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app

The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`,
`Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in
`$usernameOrToken` variable (`$password` is omitted in this particular case). For the
`Github\Client::AUTH_HTTP_PASSWORD`, you should provide the password of the account. When using `Github\Client::AUTH_URL_CLIENT_ID`
`$usernameOrToken` should contain your client ID, and `$password` should contain client secret.

After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials,
all further requests are done as the given user.
The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_ACCESS_TOKEN` and
`Github\Client::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in
this particular case).

### About authentication methods

The `Github\Client::AUTH_URL_TOKEN` authentication method sends the API token in URL parameters.
The `Github\Client::AUTH_URL_CLIENT_ID` authentication method sends the client ID and secret in URL parameters.
The `Github\Client::AUTH_HTTP_*` authentication methods send their values to GitHub using HTTP Basic Authentication.
The `Github\Client::AUTH_JWT` authentication method sends the specified JSON Web Token in an Authorization header.

`Github\Client::AUTH_URL_TOKEN` used to be the only available authentication method. To prevent existing applications
from changing their behavior in case of an API upgrade, this method is chosen as the default for this API implementation.

Note however that GitHub describes this method as deprecated. In most case you should use the
`Github\Client::AUTH_HTTP_TOKEN` instead.
After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, all
further requests are done as the given user.

### Authenticating as an Integration

Expand Down
142 changes: 0 additions & 142 deletions lib/Github/Api/Authorizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,100 +11,6 @@
*/
class Authorizations extends AbstractApi
{
use AcceptHeaderTrait;

private function configurePreviewHeader()
{
$this->acceptHeaderValue = 'application/vnd.github.doctor-strange-preview+json';
}

/**
* List all authorizations.
*
* @return array
*
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
*/
public function all()
{
return $this->get('/authorizations');
}

/**
* Show a single authorization.
*
* @param string $clientId
*
* @return array
*
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
*/
public function show($clientId)
{
return $this->get('/authorizations/'.rawurlencode($clientId));
}

/**
* Create an authorization.
*
* @param array $params
* @param string|null $OTPCode
*
* @return array
*
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
*/
public function create(array $params, $OTPCode = null)
{
$headers = null === $OTPCode ? [] : ['X-GitHub-OTP' => $OTPCode];

return $this->post('/authorizations', $params, $headers);
}

/**
* Update an authorization.
*
* @param string $clientId
* @param array $params
*
* @return array
*
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
*/
public function update($clientId, array $params)
{
return $this->patch('/authorizations/'.rawurlencode($clientId), $params);
}

/**
* Remove an authorization.
*
* @param string $clientId
*
* @return array
*
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
*/
public function remove($clientId)
{
return $this->delete('/authorizations/'.rawurlencode($clientId));
}

/**
* Check an authorization.
*
* @param string $clientId
* @param string $token
*
* @return array
*
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::checkToken() instead.
*/
public function check($clientId, $token)
{
return $this->get('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
}

/**
* Check an application token.
*
Expand All @@ -115,26 +21,9 @@ public function check($clientId, $token)
*/
public function checkToken($clientId, $token = null)
{
$this->configurePreviewHeader();

return $this->post('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []);
}

/**
* Reset an authorization.
*
* @param string $clientId
* @param string $token
*
* @return array
*
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::resetToken() instead.
*/
public function reset($clientId, $token)
{
return $this->post('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
}

/**
* Reset an application token.
*
Expand All @@ -145,36 +34,9 @@ public function reset($clientId, $token)
*/
public function resetToken($clientId, $token = null)
{
$this->configurePreviewHeader();

return $this->patch('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []);
}

/**
* Remove an authorization.
*
* @param string $clientId
* @param string $token
*
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteToken() instead.
*/
public function revoke($clientId, $token)
{
$this->delete('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
}

/**
* Revoke all authorizations.
*
* @param string $clientId
*
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteGrant() instead.
*/
public function revokeAll($clientId)
{
$this->delete('/applications/'.rawurlencode($clientId).'/tokens');
}

/**
* Revoke an application token.
*
Expand All @@ -185,8 +47,6 @@ public function revokeAll($clientId)
*/
public function deleteToken($clientId, $token = null)
{
$this->configurePreviewHeader();

$this->delete('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []);
}

Expand All @@ -200,8 +60,6 @@ public function deleteToken($clientId, $token = null)
*/
public function deleteGrant($clientId, $token = null)
{
$this->configurePreviewHeader();

$this->delete('/applications/'.rawurlencode($clientId).'/grant', $token ? ['access_token' => $token] : []);
}
}
20 changes: 0 additions & 20 deletions lib/Github/Api/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ public function watchers()
return new Watchers($this->client);
}

/**
* @deprecated Use watchers() instead
*/
public function watched($page = 1)
{
return $this->get('/user/watched', [
'page' => $page,
]);
}

/**
* @return Starring
*/
Expand All @@ -168,16 +158,6 @@ public function starring()
return new Starring($this->client);
}

/**
* @deprecated Use starring() instead
*/
public function starred($page = 1)
{
return $this->get('/user/starred', [
'page' => $page,
]);
}

/**
* @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
*/
Expand Down
Loading