Skip to content

Commit e7f1ab9

Browse files
committed
refs #955: fix CR issues
1 parent f4774d0 commit e7f1ab9

File tree

10 files changed

+37
-37
lines changed

10 files changed

+37
-37
lines changed

UPGRADE-3.0.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
### Authentication methods
1717

18-
* `Github\Client::AUTH_ACCESS_TOKEN` use `Github\AuthMethod::AUTH_ACCESS_TOKEN` instead.
19-
* `Github\Client::AUTH_CLIENT_ID` use `Github\AuthMethod::AUTH_CLIENT_ID` instead.
20-
* `Github\Client::AUTH_ACCESS_TOKEN` use `Github\AuthMethod::AUTH_ACCESS_TOKEN` instead.
21-
* `Github\Client::AUTH_ACCESS_TOKEN` use `Github\AuthMethod::AUTH_ACCESS_TOKEN` instead.
18+
* `Github\Client::AUTH_URL_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
19+
* `Github\Client::AUTH_URL_CLIENT_ID` use `Github\Client::AUTH_CLIENT_ID` instead.
20+
* `Github\Client::AUTH_HTTP_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
21+
* `Github\Client::AUTH_HTTP_PASSWORD` use `Github\Client::AUTH_ACCESS_TOKEN` instead.

doc/currentuser/repositories.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ There are three values that can be passed into the `repositories` method: `type`
2525

2626
```php
2727
$client = new \Github\Client();
28-
$client->authenticate($github_token, null, \Github\AuthMethod::AUTH_ACCESS_TOKEN);
28+
$client->authenticate($github_token, null, \Github\AuthMethod::ACCESS_TOKEN);
2929
$client->currentUser()->repositories();
3030
```

doc/graphql.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $rateLimits = $client->api('graphql')->execute($query);
1414
To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) requests must [authenticated]((../security.md)).
1515

1616
```php
17-
$client->authenticate($token, null, Github\AuthMethod::AUTH_ACCESS_TOKEN);
17+
$client->authenticate($token, null, Github\AuthMethod::ACCESS_TOKEN);
1818

1919
$result = $client->api('graphql')->execute($query);
2020
```
@@ -51,7 +51,7 @@ $variables = [
5151
'organizationLogin' => 'KnpLabs'
5252
];
5353

54-
$client->authenticate('<your-token>', null, Github\AuthMethod::AUTH_ACCESS_TOKEN);
54+
$client->authenticate('<your-token>', null, Github\AuthMethod::ACCESS_TOKEN);
5555

5656
$orgInfo = $client->api('graphql')->execute($query, $variables);
5757
```

doc/security.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ $client->authenticate($usernameOrToken, $password, $method);
1717
and guess what should contain `$password`. The `$method` can contain one of the three allowed values:
1818

1919
#### Supported methods
20-
* `Github\AuthMethod::AUTH_CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret
21-
* `Github\AuthMethod::AUTH_ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header
22-
* `Github\AuthMethod::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app
20+
* `Github\AuthMethod::CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret
21+
* `Github\AuthMethod::ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header
22+
* `Github\AuthMethod::JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app
2323

24-
The required value of `$password` depends on the chosen `$method`. For `Github\AuthMethod::AUTH_ACCESS_TOKEN`, `Github\Client::AUTH_ACCESS_TOKEN` and
25-
`Github\Client::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in
24+
The required value of `$password` depends on the chosen `$method`. For `Github\AuthMethod::CLIENT_ID`, `Github\AuthMethod::ACCESS_TOKEN` and
25+
`Github\AuthMethod::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in
2626
this particular case).
2727

28-
The `Github\Client::AUTH_JWT` authentication method sends the specified JSON Web Token in an Authorization header.
28+
The `Github\AuthMethod::JWT` authentication method sends the specified JSON Web Token in an Authorization header.
2929

3030
After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, all
3131
further requests are done as the given user.
3232

3333
### Authenticating as an Integration
3434

35-
To authenticate as an integration you need to supply a JSON Web Token with `Github\Client::AUTH_JWT` to request
36-
and installation access token which is then usable with `Github\AuthMethod::AUTH_ACCESS_TOKEN`. [Github´s integration
35+
To authenticate as an integration you need to supply a JSON Web Token with `Github\AuthMethod::JWT` to request
36+
and installation access token which is then usable with `Github\AuthMethod::ACCESS_TOKEN`. [Github´s integration
3737
authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail.
3838
It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`.
3939

@@ -64,7 +64,7 @@ $jwt = $config->builder(ChainedFormatter::withUnixTimestampDates())
6464
->getToken($config->signer(), $config->signingKey())
6565
;
6666

67-
$github->authenticate($jwt->toString(), null, Github\Client::AUTH_JWT)
67+
$github->authenticate($jwt->toString(), null, Github\AuthMethod::JWT)
6868
```
6969

7070
The `$integrationId` you can find in the about section of your github app.

lib/Github/AuthMethod.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ final class AuthMethod
99
*
1010
* @var string
1111
*/
12-
const AUTH_CLIENT_ID = 'client_id_header';
12+
const CLIENT_ID = 'client_id_header';
1313

1414
/**
1515
* Authenticate using a GitHub access token.
1616
*
1717
* @var string
1818
*/
19-
const AUTH_ACCESS_TOKEN = 'access_token_header';
19+
const ACCESS_TOKEN = 'access_token_header';
2020

2121
/**
2222
* Constant for authentication method.
@@ -26,5 +26,5 @@ final class AuthMethod
2626
*
2727
* @var string
2828
*/
29-
const AUTH_JWT = 'jwt';
29+
const JWT = 'jwt';
3030
}

lib/Github/Client.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Client
7676
*
7777
* @deprecated Use the AuthMethod const
7878
*/
79-
const AUTH_CLIENT_ID = 'client_id_header';
79+
const AUTH_CLIENT_ID = AuthMethod::CLIENT_ID;
8080

8181
/**
8282
* Authenticate using a GitHub access token.
@@ -85,7 +85,7 @@ class Client
8585
*
8686
* @deprecated Use the AuthMethod const
8787
*/
88-
const AUTH_ACCESS_TOKEN = 'access_token_header';
88+
const AUTH_ACCESS_TOKEN = AuthMethod::ACCESS_TOKEN;
8989

9090
/**
9191
* Constant for authentication method.
@@ -97,7 +97,7 @@ class Client
9797
*
9898
* @deprecated Use the AuthMethod const
9999
*/
100-
const AUTH_JWT = 'jwt';
100+
const AUTH_JWT = AuthMethod::JWT;
101101

102102
/**
103103
* @var string
@@ -319,7 +319,7 @@ public function api($name): AbstractApi
319319
*/
320320
public function authenticate($tokenOrLogin, $password = null, $authMethod = null): void
321321
{
322-
if (null === $authMethod && (AuthMethod::AUTH_JWT === $password || AuthMethod::AUTH_ACCESS_TOKEN === $password)) {
322+
if (null === $authMethod && (AuthMethod::JWT === $password || AuthMethod::ACCESS_TOKEN === $password)) {
323323
$authMethod = $password;
324324
$password = null;
325325
}

lib/Github/HttpClient/Plugin/Authentication.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
5858
private function getAuthorizationHeader(): string
5959
{
6060
switch ($this->method) {
61-
case AuthMethod::AUTH_CLIENT_ID:
61+
case AuthMethod::CLIENT_ID:
6262
return sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password));
63-
case AuthMethod::AUTH_ACCESS_TOKEN:
63+
case AuthMethod::ACCESS_TOKEN:
6464
return sprintf('token %s', $this->tokenOrLogin);
65-
case AuthMethod::AUTH_JWT:
65+
case AuthMethod::JWT:
6666
return sprintf('Bearer %s', $this->tokenOrLogin);
6767
default:
6868
throw new RuntimeException(sprintf('%s not yet implemented', $this->method));

test/Github/Tests/ClientTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $me
6969
public function getAuthenticationFullData()
7070
{
7171
return [
72-
['token', null, AuthMethod::AUTH_ACCESS_TOKEN],
73-
['client_id', 'client_secret', AuthMethod::AUTH_CLIENT_ID],
74-
['token', null, AuthMethod::AUTH_JWT],
72+
['token', null, AuthMethod::ACCESS_TOKEN],
73+
['client_id', 'client_secret', AuthMethod::CLIENT_ID],
74+
['token', null, AuthMethod::JWT],
7575
];
7676
}
7777

@@ -85,7 +85,7 @@ public function shouldAuthenticateUsingGivenParameters()
8585
->getMock();
8686
$builder->expects($this->once())
8787
->method('addPlugin')
88-
->with($this->equalTo(new Authentication('token', null, AuthMethod::AUTH_ACCESS_TOKEN)));
88+
->with($this->equalTo(new Authentication('token', null, AuthMethod::ACCESS_TOKEN)));
8989

9090
$builder->expects($this->once())
9191
->method('removePlugin')
@@ -99,7 +99,7 @@ public function shouldAuthenticateUsingGivenParameters()
9999
->method('getHttpClientBuilder')
100100
->willReturn($builder);
101101

102-
$client->authenticate('token', AuthMethod::AUTH_ACCESS_TOKEN);
102+
$client->authenticate('token', AuthMethod::ACCESS_TOKEN);
103103
}
104104

105105
/**

test/Github/Tests/Functional/CacheTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function shouldServeCachedResponse()
2626
$github = Client::createWithHttpClient($mockClient);
2727
$github->addCache(new ArrayAdapter(), ['default_ttl'=>600]);
2828

29-
$github->authenticate('fake_token_aaa', AuthMethod::AUTH_ACCESS_TOKEN);
29+
$github->authenticate('fake_token_aaa', AuthMethod::ACCESS_TOKEN);
3030
$userA = $github->currentUser()->show();
3131
$this->assertEquals('nyholm', $userA['login']);
3232

@@ -46,11 +46,11 @@ public function shouldVaryOnAuthorization()
4646
$github = Client::createWithHttpClient($mockClient);
4747
$github->addCache(new ArrayAdapter(), ['default_ttl'=>600]);
4848

49-
$github->authenticate('fake_token_aaa', AuthMethod::AUTH_ACCESS_TOKEN);
49+
$github->authenticate('fake_token_aaa', AuthMethod::ACCESS_TOKEN);
5050
$userA = $github->currentUser()->show();
5151
$this->assertEquals('nyholm', $userA['login']);
5252

53-
$github->authenticate('fake_token_bbb', AuthMethod::AUTH_ACCESS_TOKEN);
53+
$github->authenticate('fake_token_bbb', AuthMethod::ACCESS_TOKEN);
5454
$userB = $github->currentUser()->show();
5555
$this->assertEquals('octocat', $userB['login'], 'We must vary on the Authorization header.');
5656
}

test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function testAuthenticationMethods($tokenOrLogin, $password, $method, $ex
4141
public function getAuthenticationData()
4242
{
4343
return [
44-
['access_token', null, AuthMethod::AUTH_ACCESS_TOKEN, 'token access_token'],
45-
['client_id', 'client_secret', AuthMethod::AUTH_CLIENT_ID, sprintf('Basic %s', base64_encode('client_id'.':'.'client_secret'))],
46-
['jwt_token', null, AuthMethod::AUTH_JWT, 'Bearer jwt_token'],
44+
['access_token', null, AuthMethod::ACCESS_TOKEN, 'token access_token'],
45+
['client_id', 'client_secret', AuthMethod::CLIENT_ID, sprintf('Basic %s', base64_encode('client_id'.':'.'client_secret'))],
46+
['jwt_token', null, AuthMethod::JWT, 'Bearer jwt_token'],
4747
];
4848
}
4949
}

0 commit comments

Comments
 (0)