Make tokens, created by client credentials grant to live forever

This commit is contained in:
ErickSkrauch
2019-12-06 18:31:04 +03:00
parent 6fb32ec76d
commit f0a73f2b7a
8 changed files with 113 additions and 29 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace api\components\OAuth2;
use api\components\OAuth2\Keys\EmptyKey;
use Carbon\CarbonInterval;
use DateInterval;
use League\OAuth2\Server\AuthorizationServer;
use yii\base\Component as BaseComponent;
@@ -24,7 +25,7 @@ class Component extends BaseComponent {
$authCodesRepo = new Repositories\AuthCodeRepository();
$refreshTokensRepo = new Repositories\RefreshTokenRepository();
$accessTokenTTL = new DateInterval('P1D');
$accessTokenTTL = CarbonInterval::day();
$authServer = new AuthorizationServer(
$clientsRepo,
@@ -44,9 +45,8 @@ class Component extends BaseComponent {
$authServer->enableGrantType($refreshTokenGrant);
$refreshTokenGrant->setScopeRepository($publicScopesRepo); // Change repository after enabling
// TODO: make these access tokens live longer
$clientCredentialsGrant = new Grants\ClientCredentialsGrant();
$authServer->enableGrantType($clientCredentialsGrant, $accessTokenTTL);
$authServer->enableGrantType($clientCredentialsGrant, CarbonInterval::create(-1)); // set negative value to make it non expiring
$clientCredentialsGrant->setScopeRepository($internalScopesRepo); // Change repository after enabling
$this->_authServer = $authServer;