Skip to content

Commit

Permalink
updated dependency "league/oauth2-client" to 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-g committed Feb 22, 2018
1 parent 5cf038b commit fed7e8f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"jetbrains"
],
"require": {
"php": ">=5.5.0",
"league/oauth2-client": "^1.4.2"
"php": ">=7.0.0",
"league/oauth2-client": "^2.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"phpunit/phpunit": "^6.0",
"mockery/mockery": "^0.9"
},
"autoload": {
Expand Down
14 changes: 11 additions & 3 deletions src/Provider/Youtrack.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use Psr\Http\Message\ResponseInterface;
use UnexpectedValueException;

/**
* Class Youtrack
Expand Down Expand Up @@ -132,7 +133,7 @@ public function getAccessToken($grant, array $options = [])
];
$params = $grant->prepareRequestParameters($params, $options);
$request = $this->getAccessTokenRequest($params);
$response = $this->getResponse($request);
$response = $this->getParsedResponse($request);
$prepared = $this->prepareAccessTokenResponse($response);
$token = $this->createAccessToken($prepared, $grant);

Expand Down Expand Up @@ -232,7 +233,7 @@ protected function checkResponse(ResponseInterface $response, $data)
*/
protected function createResourceOwner(array $response, AccessToken $token)
{
return new YoutrackUser($response, self::ACCESS_TOKEN_RESOURCE_OWNER_ID);
return new YoutrackUser($response, $token);
}

/**
Expand All @@ -248,7 +249,14 @@ protected function fetchResourceOwnerDetails(AccessToken $token)
$options = ['body' => \GuzzleHttp\Psr7\build_query(['scope' => $this->scopes])];
$request = $this->getAuthenticatedRequest(self::METHOD_GET, $url, $token, $options);

return $this->getResponse($request);
$response = $this->getParsedResponse($request);
if (false === is_array($response)) {
throw new UnexpectedValueException(
'Invalid response received from Authorization Server. Expected JSON.'
);
}

return $response;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/Provider/YoutrackUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTime;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Tool\ArrayAccessorTrait;

/**
Expand All @@ -17,14 +18,20 @@ class YoutrackUser implements ResourceOwnerInterface
* @var array
*/
protected $response;
/**
* @var AccessToken
*/
protected $token;

/**
* YoutrackUser constructor.
* @param array $response
* @param AccessToken $token
*/
public function __construct(array $response)
public function __construct(array $response, AccessToken $token)
{
$this->response = $response;
$this->token = $token;
}

/**
Expand Down Expand Up @@ -141,6 +148,14 @@ public function getId()
return $this->response['id'];
}

/**
* @return AccessToken
*/
public function getToken(): AccessToken
{
return $this->token;
}

/**
* Return all of the owner details available as an array.
*
Expand Down
14 changes: 8 additions & 6 deletions test/src/Provider/YoutrackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use MarkusG\OAuth2\Client\Provider\Youtrack;
use MarkusG\OAuth2\Client\Provider\YoutrackUser;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class YoutrackTest extends \PHPUnit_Framework_TestCase
class YoutrackTest extends TestCase
{
protected $provider;

Expand Down Expand Up @@ -41,10 +42,11 @@ public function testAuthorizationUrl()

public function testScopes()
{
$options = ['scope' => [uniqid(),uniqid()]];
$options = ['scope' => [uniqid(), uniqid()]];
$url = $this->provider->getAuthorizationUrl($options);
$this->assertContains(urlencode(implode(' ', $options['scope'])), $url);
$this->assertContains(rawurlencode(implode(' ', $options['scope'])), $url);
}

public function testGetAuthorizationUrl()
{
$url = $this->provider->getAuthorizationUrl();
Expand All @@ -59,6 +61,7 @@ public function testGetBaseAccessTokenUrl()
$uri = parse_url($url);
$this->assertEquals('/hub/api/rest/oauth2/token', $uri['path']);
}

public function testGetAccessToken()
{
$response = m::mock('Psr\Http\Message\ResponseInterface');
Expand All @@ -77,7 +80,7 @@ public function testGetAccessToken()

public function testUserData()
{
$userId = rand(1000,9999);
$userId = rand(1000, 9999);
$name = uniqid();
$login = uniqid();
$type = uniqid();
Expand All @@ -86,7 +89,7 @@ public function testUserData()
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'application/x-www-form-urlencoded']);
$postResponse->shouldReceive('getStatusCode')->andReturn(200);
$userResponse = m::mock('Psr\Http\Message\ResponseInterface');
$userResponse->shouldReceive('getBody')->andReturn('{"id": '.$userId.', "login": "'.$login.'", "name": "'.$name.'", "type": "'.$type.'"}');
$userResponse->shouldReceive('getBody')->andReturn('{"id": ' . $userId . ', "login": "' . $login . '", "name": "' . $name . '", "type": "' . $type . '"}');
$userResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
$userResponse->shouldReceive('getStatusCode')->andReturn(200);
$client = m::mock('GuzzleHttp\ClientInterface');
Expand All @@ -108,5 +111,4 @@ public function testUserData()
}



}

0 comments on commit fed7e8f

Please sign in to comment.