Skip to content

Commit a521eef

Browse files
authored
Merge pull request #12 from npr/features/hostnames-plus
Authorization Service hostname change, plus other breaking changes
2 parents 6fa5016 + e49de37 commit a521eef

28 files changed

+180
-142
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
sudo: false
22
language: php
33
php:
4-
- '5.5'
54
- '5.6'
65
- '7.0'
76
- '7.1'
7+
- '7.2'
88
- hhvm
99
notifications:
1010
email: false

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ This project includes tests which can be executed with PHPUnit.
6868

6969
- `./vendor/bin/phpunit`: runs all unit tests
7070

71-
PHPUnit is configured to generate coverage reports in a `coverage` folder under `test-results` in the root of the project. Overall test coverage can viewed by opening `test-results/coverage/index.html`. (N.B. These coverage reports are purposely excluded from source control.) Note that [Xdebug must be enabled](https://xdebug.org/docs/install) in order for code coverage to be generated.
71+
PHPUnit is configured to generate coverage reports in a `coverage` folder under `test-results` in the root of the project. (N.B. These coverage reports are purposely excluded from source control.) Note that [Xdebug must be enabled](https://xdebug.org/docs/install) in order for code coverage to be generated.
7272

7373
XML files are also generated for reporting test results and coverage on a CI server; again, those can be found under `test-results`.
7474

README.md

Lines changed: 18 additions & 18 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "npr/npr-one-backend-proxy",
33
"description": "A server-side proxy for interacting with the NPR One API's authorization server",
4-
"version": "1.1.2",
4+
"version": "2.0.0",
55
"keywords": [
66
"npr",
77
"oauth",
@@ -38,11 +38,11 @@
3838
},
3939
"autoload": {
4040
"psr-4": {
41-
"NPR\\": "src/"
41+
"NPR\\One\\": "src/"
4242
}
4343
},
4444
"require": {
45-
"php": ">=5.5.0",
45+
"php": ">=5.6.0",
4646
"guzzlehttp/guzzle": "~6.0",
4747
"php-di/php-di": "^5.2"
4848
},

docs/NPR-One-Interfaces-ConfigInterface.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ grant type. Currently, client credentials tokens never expire, so hard-coding it
6666

6767

6868

69-
### getNprApiHost
69+
### getNprAuthorizationServiceHost
7070

71-
string NPR\One\Interfaces\ConfigInterface::getNprApiHost()
72-
73-
Returns the NPR One API Hostname, useful for testing on staging environments. Most consumers will want to
74-
hard-code this to always return `https://api.npr.org`. Please do not include a trailing slash.
71+
string NPR\One\Interfaces\ConfigInterface::getNprAuthorizationServiceHost()
7572

73+
Returns the NPR One Authorization Service hostname, useful for testing on staging environments.
7674

75+
Most consumers will want to hard-code this to always return `https://authorization.api.npr.org`.
76+
Please do not include a trailing slash.
7777

7878
* Visibility: **public**
7979

examples/ConfigProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function getClientCredentialsToken()
3535
/**
3636
* @inheritdoc
3737
*/
38-
public function getNprApiHost()
38+
public function getNprAuthorizationServiceHost()
3939
{
40-
return 'https://api.npr.org';
40+
return 'https://authorization.api.npr.org';
4141
}
4242

4343
/**

phpunit.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
</whitelist>
2424
</filter>
2525
<logging>
26-
<log type="coverage-html" target="test-results/coverage" lowUpperBound="35" highLowerBound="70"/>
2726
<log type="coverage-clover" target="test-results/coverage.xml"/>
2827
<log type="junit" target="test-results/junit.xml" logIncompleteSkipped="false"/>
2928
</logging>

src/One/Controllers/AbstractOAuth2Controller.php renamed to src/Controllers/AbstractOAuth2Controller.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace NPR\One\Controllers;
44

55
use GuzzleHttp\Client;
6-
use GuzzleHttp\Psr7\Response;
76
use NPR\One\DI\DI;
87
use NPR\One\Exceptions\ApiException;
98
use NPR\One\Interfaces\ConfigInterface;
109
use NPR\One\Interfaces\EncryptionInterface;
1110
use NPR\One\Interfaces\StorageInterface;
1211
use NPR\One\Models\AccessTokenModel;
1312
use NPR\One\Providers\CookieProvider;
13+
use NPR\One\Providers\EncryptionProvider;
1414
use NPR\One\Providers\SecureCookieProvider;
1515

1616

@@ -54,8 +54,8 @@ public function __construct()
5454
'X-Longitude' => $_SERVER['GEOIP_LONGITUDE']
5555
];
5656
}
57-
$this->encryption = DI::container()->get('NPR\One\Providers\EncryptionProvider');
58-
$this->secureStorage = DI::container()->get('NPR\One\Providers\SecureCookieProvider');
57+
$this->encryption = DI::container()->get(EncryptionProvider::class);
58+
$this->secureStorage = DI::container()->get(SecureCookieProvider::class);
5959
$this->secureStorage->setEncryptionProvider($this->encryption);
6060
}
6161

@@ -211,6 +211,8 @@ final protected function validateScopes(array $scopes)
211211
* @return AccessTokenModel
212212
* @throws \InvalidArgumentException
213213
* @throws ApiException
214+
* @throws \Exception
215+
* @throws \GuzzleHttp\Exception\GuzzleException
214216
*/
215217
final protected function createAccessToken($grantType, $additionalParams = [])
216218
{
@@ -222,8 +224,8 @@ final protected function createAccessToken($grantType, $additionalParams = [])
222224
$this->ensureExternalProvidersExist();
223225

224226
/** @var Client $client */
225-
$client = DI::container()->get('GuzzleHttp\Client');
226-
$response = $client->request('POST', $this->config->getNprApiHost() . '/authorization/v2/token', [
227+
$client = DI::container()->get(Client::class);
228+
$response = $client->request('POST', $this->config->getNprAuthorizationServiceHost() . '/v2/token', [
227229
'headers' => $this->headers,
228230
'form_params' => array_merge([
229231
'client_id' => $this->config->getClientId(),

src/One/Controllers/AuthCodeController.php renamed to src/Controllers/AuthCodeController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AuthCodeController extends AbstractOAuth2Controller
3636
public function __construct()
3737
{
3838
parent::__construct();
39-
$this->cookies = DI::container()->get('NPR\One\Providers\CookieProvider');
39+
$this->cookies = DI::container()->get(CookieProvider::class);
4040
}
4141

4242
/**
@@ -111,7 +111,7 @@ public function startAuthorizationGrant(array $scopes)
111111
'scope' => join(' ', $scopes)
112112
];
113113

114-
return $this->getConfigProvider()->getNprApiHost() . '/authorization/v2/authorize?' . http_build_query($queryParams);
114+
return $this->getConfigProvider()->getNprAuthorizationServiceHost() . '/v2/authorize?' . http_build_query($queryParams);
115115
}
116116

117117
/**
@@ -123,6 +123,7 @@ public function startAuthorizationGrant(array $scopes)
123123
* @return AccessTokenModel - useful for debugging
124124
* @throws \InvalidArgumentException
125125
* @throws \Exception when state param is invalid
126+
* @throws \GuzzleHttp\Exception\GuzzleException
126127
*/
127128
public function completeAuthorizationGrant($authorizationCode, $state)
128129
{

src/One/Controllers/DeviceCodeController.php renamed to src/Controllers/DeviceCodeController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class DeviceCodeController extends AbstractOAuth2Controller
2727
* @return DeviceCodeModel
2828
* @throws \InvalidArgumentException
2929
* @throws \Exception
30+
* @throws \GuzzleHttp\Exception\GuzzleException
3031
*/
3132
public function startDeviceCodeGrant(array $scopes)
3233
{
@@ -48,6 +49,7 @@ public function startDeviceCodeGrant(array $scopes)
4849
* @api
4950
* @return AccessTokenModel
5051
* @throws \Exception
52+
* @throws \GuzzleHttp\Exception\GuzzleException
5153
*/
5254
public function pollDeviceCodeGrant()
5355
{
@@ -76,12 +78,14 @@ public function pollDeviceCodeGrant()
7678
* @param string[] $scopes
7779
* @return DeviceCodeModel
7880
* @throws ApiException
81+
* @throws \Exception
82+
* @throws \GuzzleHttp\Exception\GuzzleException
7983
*/
8084
private function createDeviceCode(array $scopes)
8185
{
8286
/** @var Client $client */
83-
$client = DI::container()->get('GuzzleHttp\Client');
84-
$response = $client->request('POST', $this->getConfigProvider()->getNprApiHost() . '/authorization/v2/device', [
87+
$client = DI::container()->get(Client::class);
88+
$response = $client->request('POST', $this->getConfigProvider()->getNprAuthorizationServiceHost() . '/v2/device', [
8589
'headers' => $this->getHeaders(),
8690
'form_params' => [
8791
'client_id' => $this->getConfigProvider()->getClientId(),

src/One/Controllers/LogoutController.php renamed to src/Controllers/LogoutController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class LogoutController extends AbstractOAuth2Controller
2626
* @api
2727
* @param string|null $accessToken
2828
* @throws \Exception if no access token is passed in and no refresh token is found in the secure storage layer
29+
* @throws \GuzzleHttp\Exception\GuzzleException
2930
*/
3031
public function deleteAccessAndRefreshTokens($accessToken = null)
3132
{
@@ -55,6 +56,7 @@ public function deleteAccessAndRefreshTokens($accessToken = null)
5556
* @param string $token
5657
* @param bool $isRefreshToken
5758
* @throws ApiException
59+
* @throws \GuzzleHttp\Exception\GuzzleException
5860
*/
5961
private function revokeToken($token, $isRefreshToken = false)
6062
{
@@ -72,8 +74,8 @@ private function revokeToken($token, $isRefreshToken = false)
7274
}
7375

7476
/** @var Client $client */
75-
$client = DI::container()->get('GuzzleHttp\Client');
76-
$response = $client->request('POST', $this->getConfigProvider()->getNprApiHost() . '/authorization/v2/token/revoke', [
77+
$client = DI::container()->get(Client::class);
78+
$response = $client->request('POST', $this->getConfigProvider()->getNprAuthorizationServiceHost() . '/v2/token/revoke', [
7779
'headers' => [
7880
'Authorization' => 'Bearer ' . $this->getConfigProvider()->getClientCredentialsToken()
7981
],

src/One/Controllers/RefreshTokenController.php renamed to src/Controllers/RefreshTokenController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class RefreshTokenController extends AbstractOAuth2Controller
2222
* @api
2323
* @return AccessTokenModel
2424
* @throws \Exception
25+
* @throws \GuzzleHttp\Exception\GuzzleException
2526
*/
2627
public function generateNewAccessTokenFromRefreshToken()
2728
{
File renamed without changes.
File renamed without changes.

src/One/Interfaces/ConfigInterface.php renamed to src/Interfaces/ConfigInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ public function getClientSecret();
4242
public function getClientCredentialsToken();
4343

4444
/**
45-
* Returns the NPR One API Hostname, useful for testing on staging environments. Most consumers will want to
46-
* hard-code this to always return `https://api.npr.org`. Please do not include a trailing slash.
45+
* Returns the NPR One Authorization Service hostname, useful for testing on staging environments.
46+
* Most consumers will want to hard-code this to always return `https://authorization.api.npr.org`.
47+
* Please do not include a trailing slash.
4748
*
4849
* @return string
4950
*/
50-
public function getNprApiHost();
51+
public function getNprAuthorizationServiceHost();
5152

5253
/**
5354
* Returns the host (or path) of the NPR One application (the client/frontend). This is where the `authorization_code`
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/One/Providers/EncryptionProvider.php renamed to src/Providers/EncryptionProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function isValid()
3939

4040
/**
4141
* {@inheritdoc}
42+
* @throws \Exception
4243
*/
4344
public function encrypt($value)
4445
{
@@ -68,6 +69,7 @@ public function encrypt($value)
6869

6970
/**
7071
* {@inheritdoc}
72+
* @throws \Exception
7173
*/
7274
public function decrypt($value)
7375
{

0 commit comments

Comments
 (0)