Skip to content

Commit

Permalink
Use BearerAuthorizationTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
tgallice committed Mar 10, 2016
1 parent 8fb30ea commit 17b65c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
15 changes: 4 additions & 11 deletions src/Provider/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use Psr\Http\Message\ResponseInterface;
use Tgallice\OAuth2\Client\Provider\Exception\BufferProviderException;

class Buffer extends AbstractProvider
{
use BearerAuthorizationTrait;

/**
* Buffer app base url
*
Expand Down Expand Up @@ -51,7 +54,7 @@ public function getBaseAccessTokenUrl(array $params)
*/
public function getResourceOwnerDetailsUrl(AccessToken $token)
{
return $this->getApiUrl() . '/user.json?access_token=' . $token;
return $this->getApiUrl() . '/user.json';
}

/**
Expand All @@ -72,16 +75,6 @@ protected function getDefaultScopes()
return [];
}

/**
* @inheritdoc
*/
protected function getAuthorizationHeaders($token = null)
{
return [
'Authorization' => 'Bearer '. (string) $token,
];
}

/**
* @inheritdoc
*/
Expand Down
16 changes: 6 additions & 10 deletions tests/Provider/BufferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function testGetBaseAccessTokenUrl()

public function testGetUrlUserDetails()
{
$token = $this->getAccessToken('token');
$this->assertEquals($this->provider->getApiUrl() . '/user.json?access_token=token', $this->provider->getResourceOwnerDetailsUrl($token));
$token = $this->getAccessToken();
$this->assertEquals($this->provider->getApiUrl() . '/user.json', $this->provider->getResourceOwnerDetailsUrl($token));
}

public function testAuthorizationUrl()
Expand Down Expand Up @@ -97,10 +97,8 @@ public function testGetAccessToken()
}

/**
*
* @expectedException Tgallice\OAuth2\Client\Provider\Exception\BufferProviderException
*
**/
* @expectedException \Tgallice\OAuth2\Client\Provider\Exception\BufferProviderException
*/
public function testExceptionThrownWhenErrorObjectReceived()
{
$response = $this->prophesize(ResponseInterface::class);
Expand All @@ -117,12 +115,10 @@ public function testExceptionThrownWhenErrorObjectReceived()
}

/**
* @param null $tokenValue
*
* @return AccessToken
*/
private function getAccessToken($tokenValue = 'token')
private function getAccessToken()
{
return new AccessToken(['access_token' => $tokenValue]);
return $this->prophesize(AccessToken::class)->reveal();
}
}

0 comments on commit 17b65c9

Please sign in to comment.