Skip to content

Commit 379c50c

Browse files
authored
Merge pull request #23 from bwaidelich/feature/22-token-default-lifetime
FEATURE: Token default lifetime
2 parents 0e6a9d9 + 7a90a66 commit 379c50c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Classes/OAuthClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ abstract class OAuthClient
7575
*/
7676
protected $garbageCollectionProbability;
7777

78+
/**
79+
* @Flow\InjectConfiguration(path="token.defaultLifetime", package="Flownative.OAuth2.Client")
80+
* @var int|null
81+
*/
82+
protected $defaultTokenLifetime;
83+
7884
/**
7985
* @var Client
8086
*/
@@ -261,6 +267,10 @@ public function startAuthorization(string $clientId, string $clientSecret, UriIn
261267
{
262268
$authorizationId = Authorization::generateAuthorizationIdForAuthorizationCodeGrant($this->getServiceType(), $this->getServiceName(), $clientId);
263269
$authorization = new Authorization($authorizationId, $this->getServiceType(), $clientId, Authorization::GRANT_AUTHORIZATION_CODE, $scope);
270+
if ($this->defaultTokenLifetime !== null) {
271+
$authorization->setExpires(new \DateTimeImmutable('+ ' . $this->defaultTokenLifetime . ' seconds'));
272+
}
273+
264274
$this->logger->info(sprintf('OAuth (%s): Starting authorization %s using client id "%s", a %s bytes long secret and scope "%s".', $this->getServiceType(), $authorization->getAuthorizationId(), $clientId, strlen($clientSecret), $scope));
265275

266276
try {

Configuration/Settings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Flownative:
1313
services: []
1414
# - name: 'flownative-beach'
1515
# className: 'Flownative\Beach\BeachClient'
16+
token:
17+
18+
# default lifetime of new tokens in seconds
19+
defaultLifetime: ~
1620
encryption:
1721

1822
# A base64-encoded random key, for example generated with ./flow oauth:generateencryptionkey

0 commit comments

Comments
 (0)