Skip to content

Commit df37d19

Browse files
authored
Merge pull request #16 from flownative/bugfix/expires-property
BUGFIX: Make expires an explicit property of Authorization
2 parents ac4aabc + 9696845 commit df37d19

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

Classes/Authorization.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class Authorization
5858
*/
5959
protected $scope;
6060

61+
/**
62+
* @var \DateTimeImmutable
63+
* @ORM\Column(nullable = true)
64+
*/
65+
protected $expires;
66+
6167
/**
6268
* @var string
6369
* @ORM\Column(nullable = true, type = "text")
@@ -209,4 +215,20 @@ public function getAccessToken(): ?AccessToken
209215
}
210216
return null;
211217
}
218+
219+
/**
220+
* @return \DateTimeImmutable
221+
*/
222+
public function getExpires(): ?\DateTimeImmutable
223+
{
224+
return $this->expires;
225+
}
226+
227+
/**
228+
* @param \DateTimeImmutable $expires
229+
*/
230+
public function setExpires(\DateTimeImmutable $expires): void
231+
{
232+
$this->expires = $expires;
233+
}
212234
}

Classes/OAuthClient.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Neos\Flow\Annotations as Flow;
1717
use Neos\Flow\Core\Bootstrap;
1818
use Neos\Flow\Http\HttpRequestHandlerInterface;
19+
use Neos\Flow\Log\Utility\LogEnvironment;
1920
use Neos\Flow\Mvc\ActionRequest;
2021
use Neos\Flow\Mvc\Routing\Exception\MissingActionNameException;
2122
use Neos\Flow\Mvc\Routing\UriBuilder;
@@ -233,14 +234,14 @@ public function requestAccessToken(string $serviceName, string $clientId, string
233234
$this->entityManager->remove($existingAuthorization);
234235
$this->entityManager->flush();
235236

236-
$this->logger->info(sprintf('OAuth (%s): Removed old OAuth token for client "%s". (authorization id: %s)', $this->getServiceType(), $clientId, $authorizationId));
237+
$this->logger->info(sprintf('OAuth (%s): Removed old OAuth token for client "%s". (authorization id: %s)', $this->getServiceType(), $clientId, $authorizationId), LogEnvironment::fromMethodName(__METHOD__));
237238
}
238239

239240
$accessToken = $this->createOAuthProvider($clientId, $clientSecret)->getAccessToken(Authorization::GRANT_CLIENT_CREDENTIALS, $additionalParameters);
240241
$authorization = new Authorization($authorizationId, $serviceName, $clientId, Authorization::GRANT_CLIENT_CREDENTIALS, $scope);
241242
$authorization->setAccessToken($accessToken);
242243

243-
$this->logger->info(sprintf('OAuth (%s): Persisted new OAuth authorization %s for client "%s" with expiry time %s. (authorization id: %s)', $this->getServiceType(), $authorizationId, $clientId, $accessToken->getExpires(), $authorizationId));
244+
$this->logger->info(sprintf('OAuth (%s): Persisted new OAuth authorization %s for client "%s" with expiry time %s. (authorization id: %s)', $this->getServiceType(), $authorizationId, $clientId, $accessToken->getExpires(), $authorizationId), LogEnvironment::fromMethodName(__METHOD__));
244245

245246
$this->entityManager->persist($authorization);
246247
$this->entityManager->flush();
@@ -377,7 +378,7 @@ public function refreshAuthorization(string $authorizationId, string $clientId,
377378
try {
378379
$accessToken = $oAuthProvider->getAccessToken('refresh_token', ['refresh_token' => $authorization->refreshToken]);
379380
$authorization->accessToken = $accessToken->getToken();
380-
$authorization->expires = ($accessToken->getExpires() ? \DateTimeImmutable::createFromFormat('U', $accessToken->getExpires()) : null);
381+
$authorization->setExpires($accessToken->getExpires() ? \DateTimeImmutable::createFromFormat('U', $accessToken->getExpires()) : null);
381382

382383
$this->logger->debug(sprintf($this->getServiceType() . ': New access token is "%s", refresh token is "%s".', $authorization->accessToken, $authorization->refreshToken));
383384

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace Neos\Flow\Persistence\Doctrine\Migrations;
3+
4+
use Doctrine\Migrations\AbstractMigration;
5+
use Doctrine\DBAL\Schema\Schema;
6+
use Doctrine\DBAL\Migrations\AbortMigrationException;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs! This block will be used as the migration description if getDescription() is not used.
10+
*/
11+
class Version20200716150451 extends AbstractMigration
12+
{
13+
14+
/**
15+
* @return string
16+
*/
17+
public function getDescription(): string
18+
{
19+
return '';
20+
}
21+
22+
/**
23+
* @param Schema $schema
24+
* @return void
25+
* @throws AbortMigrationException
26+
*/
27+
public function up(Schema $schema): void
28+
{
29+
// this up() migration is autogenerated, please modify it to your needs
30+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
31+
$this->addSql('ALTER TABLE flownative_oauth2_client_authorization ADD expires DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
32+
}
33+
34+
/**
35+
* @param Schema $schema
36+
* @return void
37+
* @throws AbortMigrationException
38+
*/
39+
public function down(Schema $schema): void
40+
{
41+
// this down() migration is autogenerated, please modify it to your needs
42+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
43+
44+
$this->addSql('ALTER TABLE flownative_oauth2_client_authorization DROP expires');
45+
}
46+
}

0 commit comments

Comments
 (0)