Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 7b7be95

Browse files
committed
🚿
1 parent 493f4d7 commit 7b7be95

File tree

9 files changed

+29
-14
lines changed

9 files changed

+29
-14
lines changed

src/Core/OAuth1Provider.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ protected function nonce():string{
115115
$nonce = random_bytes(32);
116116

117117
// use the sodium extension if available
118-
/** @noinspection PhpComposerExtensionStubsInspection */
119118
return function_exists('sodium_bin2hex') ? sodium_bin2hex($nonce) : bin2hex($nonce);
120119
}
121120

@@ -175,9 +174,9 @@ public function getAccessToken(string $token, string $verifier):AccessToken{
175174
* @return \Psr\Http\Message\RequestInterface
176175
*/
177176
public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
178-
$u = $request->getUri();
177+
$uri = $request->getUri();
179178

180-
parse_str($u->getQuery(), $p);
179+
parse_str($uri->getQuery(), $query);
181180

182181
$parameters = [
183182
'oauth_consumer_key' => $this->options->key,
@@ -188,7 +187,12 @@ public function getRequestAuthorization(RequestInterface $request, AccessToken $
188187
'oauth_version' => '1.0',
189188
];
190189

191-
$parameters['oauth_signature'] = $this->getSignature((string)$u->withQuery('')->withFragment(''), array_merge($p, $parameters), $request->getMethod(), $token->accessTokenSecret);
190+
$parameters['oauth_signature'] = $this->getSignature(
191+
(string)$uri->withQuery('')->withFragment(''),
192+
array_merge($query, $parameters),
193+
$request->getMethod(),
194+
$token->accessTokenSecret
195+
);
192196

193197
return $request->withHeader('Authorization', 'OAuth '.Psr7\build_http_query($parameters, true, ', ', '"'));
194198
}

src/Core/OAuth2ClientCredentialsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @property string $clientCredentialsTokenURL
2121
* @property string $accessTokenURL
2222
* @property \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
23-
* @property \chillerlan\HTTP\HTTPClientInterface $http
23+
* @property \chillerlan\HTTP\Psr18\HTTPClientInterface $http
2424
* @property \Psr\Http\Message\RequestFactoryInterface $requestFactory
2525
* @property \Psr\Http\Message\StreamFactoryInterface $streamFactory
2626
*/

src/Core/OAuth2Interface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace chillerlan\OAuth\Core;
1414

15+
use Psr\Http\Message\UriInterface;
16+
1517
interface OAuth2Interface extends OAuthInterface{
1618

1719
const HEADER_OAUTH = 0;
@@ -43,4 +45,13 @@ interface OAuth2Interface extends OAuthInterface{
4345
*/
4446
public function getAccessToken(string $code, string $state = null):AccessToken;
4547

48+
/**
49+
* @param array|null $params
50+
* @param array|null $scopes
51+
*
52+
* @return \Psr\Http\Message\UriInterface
53+
*/
54+
public function getAuthURL(array $params = null, array $scopes = null):UriInterface;
55+
56+
4657
}

src/Core/OAuth2Provider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getAuthURL(array $params = null, array $scopes = null):UriInterf
8585
* @throws \chillerlan\OAuth\Core\ProviderException
8686
*/
8787
protected function parseTokenResponse(ResponseInterface $response):AccessToken{
88-
$data = json_decode($response->getBody()->getContents(), true);
88+
$data = Psr7\get_json($response, true);
8989

9090
if(!is_array($data)){
9191
throw new ProviderException('unable to parse token response');
@@ -162,10 +162,10 @@ public function getAccessToken(string $code, string $state = null):AccessToken{
162162
*/
163163
public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
164164

165-
if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){
165+
if(array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)){
166166
$request = $request->withHeader('Authorization', $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken);
167167
}
168-
elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
168+
elseif(array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){
169169
$uri = Psr7\merge_query((string)$request->getUri(), [$this::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]);
170170

171171
$request = $request->withUri($this->uriFactory->createUri($uri));

src/Core/OAuth2TokenRefreshTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @property string $refreshTokenURL
2121
* @property \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
2222
* @property \chillerlan\OAuth\OAuthOptions $options
23-
* @property \chillerlan\HTTP\HTTPClientInterface $http
23+
* @property \chillerlan\HTTP\Psr18\HTTPClientInterface $http
2424
* @property \Psr\Http\Message\RequestFactoryInterface $requestFactory
2525
* @property \Psr\Http\Message\StreamFactoryInterface $streamFactory
2626
*/

src/Core/OAuthInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getAuthURL(array $params = null):UriInterface;
3838
* @param \chillerlan\OAuth\Core\AccessToken $token
3939
*
4040
* @return \Psr\Http\Message\RequestInterface
41+
* @internal
4142
*/
4243
public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface;
4344

src/OAuthOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
* HTTPOptionsTrait
3232
*
3333
* @property string $user_agent
34-
* @property int $timeout
3534
* @property array $curl_options
3635
* @property string $ca_info
37-
* @property int $max_redirects
36+
* @property bool $ssl_verifypeer
37+
* @property string $curlHandle
3838
*/
3939
class OAuthOptions extends SettingsContainerAbstract{
4040
use OAuthOptionsTrait, HTTPOptionsTrait;

src/Storage/OAuthStorageInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
interface OAuthStorageInterface{
1818

19-
public const TOKEN_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
19+
const TOKEN_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
2020

2121
/**
2222
* @param string $service

tests/API/OAuth2APITestAbstract.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testRequestCredentialsToken(){
3434
$token = $this->provider->getClientCredentialsToken();
3535

3636
$this->assertInstanceOf(AccessToken::class, $token);
37-
$this->assertInternalType('string', $token->accessToken);
37+
$this->assertIsString($token->accessToken);
3838

3939
if($token->expires !== AccessToken::EOL_NEVER_EXPIRES){
4040
$this->assertGreaterThan(time(), $token->expires);
@@ -43,5 +43,4 @@ public function testRequestCredentialsToken(){
4343
$this->logger->debug('OAuth2ClientCredentials', $token->toArray());
4444
}
4545

46-
4746
}

0 commit comments

Comments
 (0)