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

Commit 69f65d1

Browse files
committed
🚿
1 parent f0c411a commit 69f65d1

7 files changed

+15
-17
lines changed

src/Core/AccessToken.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ public function setExpiry(int $expires = null):AccessToken{
119119
$expires = intval($expires);
120120
}
121121

122-
$this->expires = $this::EOL_UNKNOWN;
122+
$this->expires = self::EOL_UNKNOWN;
123123

124-
if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){
125-
$this->expires = $this::EOL_NEVER_EXPIRES;
124+
if($expires === 0 || $expires === self::EOL_NEVER_EXPIRES){
125+
$this->expires = self::EOL_NEVER_EXPIRES;
126126
}
127127
elseif($expires > $now){
128128
$this->expires = $expires;
129129
}
130-
elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
130+
elseif($expires > 0 && $expires < self::EXPIRY_MAX){
131131
$this->expires = $now + $expires;
132132
}
133133

@@ -138,7 +138,7 @@ public function setExpiry(int $expires = null):AccessToken{
138138
* @return bool
139139
*/
140140
public function isExpired():bool{
141-
return $this->expires !== $this::EOL_NEVER_EXPIRES && $this->expires !== $this::EOL_UNKNOWN && time() > $this->expires;
141+
return $this->expires !== self::EOL_NEVER_EXPIRES && $this->expires !== self::EOL_UNKNOWN && time() > $this->expires;
142142
}
143143

144144
}

src/Core/OAuth2Provider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ public function getAccessToken(string $code, string $state = null):AccessToken{
163163
public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
164164

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

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

src/Core/OAuthProvider.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use chillerlan\Settings\SettingsContainerInterface;
2020
use Psr\Http\Client\ClientInterface;
2121
use Psr\Http\Message\{RequestFactoryInterface, ResponseInterface, StreamFactoryInterface, StreamInterface, UriFactoryInterface};
22-
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, NullLogger};
22+
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
2323
use ReflectionClass;
2424

2525
/**
@@ -118,15 +118,16 @@ abstract class OAuthProvider implements OAuthInterface, ApiClientInterface, Logg
118118
* @param \Psr\Http\Client\ClientInterface $http
119119
* @param \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
120120
* @param \chillerlan\Settings\SettingsContainerInterface $options
121+
* @param \Psr\Log\LoggerInterface|null $logger
121122
*
122123
* @throws \chillerlan\HTTP\MagicAPI\ApiClientException
123124
*/
124-
public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options){
125+
public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){
125126
$this->http = $http;
126127
$this->storage = $storage;
127128
$this->options = $options;
129+
$this->logger = $logger ?? new NullLogger;
128130

129-
$this->logger = new NullLogger;
130131
$this->requestFactory = new RequestFactory;
131132
$this->streamFactory = new StreamFactory;
132133
$this->uriFactory = new UriFactory;

src/Storage/OAuthStorageAbstract.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function toStorage(AccessToken $token):string {
4747
/**
4848
* @param string $data
4949
*
50-
* @return \chillerlan\OAuth\Core\AccessToken
50+
* @return \chillerlan\OAuth\Core\AccessToken|\chillerlan\Settings\SettingsContainerInterface
5151
*/
5252
public function fromStorage(string $data):AccessToken{
5353
return (new AccessToken)->fromJSON($data);

src/Storage/OAuthStorageInterface.php

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
interface OAuthStorageInterface{
1818

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";
20-
2119
/**
2220
* @param string $service
2321
* @param \chillerlan\OAuth\Core\AccessToken $token

src/Storage/SessionStorage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(SettingsContainerInterface $options = null){
4141
parent::__construct($options);
4242

4343
$this->sessionVar = $this->options->sessionTokenVar;
44-
$this->stateVar = $this->options->sessionStateVar;
44+
$this->stateVar = $this->options->sessionStateVar;
4545

4646
// Determine if the session has started.
4747
// @link http://stackoverflow.com/a/18542272/1470961
@@ -92,7 +92,7 @@ public function storeAccessToken(string $service, AccessToken $token):OAuthStora
9292
/**
9393
* @param string $service
9494
*
95-
* @return \chillerlan\OAuth\Core\AccessToken
95+
* @return \chillerlan\OAuth\Core\AccessToken|\chillerlan\Settings\SettingsContainerInterface
9696
* @throws \chillerlan\OAuth\Storage\OAuthStorageException
9797
*/
9898
public function getAccessToken(string $service):AccessToken{

tests/API/APITestAbstract.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ protected function setUp(){
9393
$this->logger = $this->initLog($options);
9494
$http = $this->initHttp($options, $this->logger);
9595
$this->storage = new MemoryStorage;
96-
$this->provider = new $this->FQN($http, $this->storage, $options);
97-
$this->provider->setLogger($this->logger);
96+
$this->provider = new $this->FQN($http, $this->storage, $options, $this->logger);
9897

9998
$tokenfile = $this->CFG.'/'.$this->provider->serviceName.'.token.json';
10099
$token = is_file($tokenfile)

0 commit comments

Comments
 (0)