Some progress [skip ci]

This commit is contained in:
ErickSkrauch
2024-12-06 17:35:16 +01:00
parent 5ed6f0ce86
commit 157e4cae5f
7 changed files with 55 additions and 52 deletions

View File

@@ -6,6 +6,7 @@ namespace common\components\OAuth2;
use Carbon\CarbonInterval; use Carbon\CarbonInterval;
use DateInterval; use DateInterval;
use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Grant\DeviceCodeGrant;
use yii\base\Component as BaseComponent; use yii\base\Component as BaseComponent;
final class AuthorizationServerFactory extends BaseComponent { final class AuthorizationServerFactory extends BaseComponent {
@@ -17,6 +18,7 @@ final class AuthorizationServerFactory extends BaseComponent {
$internalScopesRepo = new Repositories\InternalScopeRepository(); $internalScopesRepo = new Repositories\InternalScopeRepository();
$authCodesRepo = new Repositories\AuthCodeRepository(); $authCodesRepo = new Repositories\AuthCodeRepository();
$refreshTokensRepo = new Repositories\RefreshTokenRepository(); $refreshTokensRepo = new Repositories\RefreshTokenRepository();
$deviceCodesRepo = new Repositories\DeviceCodeRepository();
$accessTokenTTL = CarbonInterval::create(-1); // Set negative value to make tokens non expiring $accessTokenTTL = CarbonInterval::create(-1); // Set negative value to make tokens non expiring
@@ -42,6 +44,11 @@ final class AuthorizationServerFactory extends BaseComponent {
$authServer->enableGrantType($clientCredentialsGrant, $accessTokenTTL); $authServer->enableGrantType($clientCredentialsGrant, $accessTokenTTL);
$clientCredentialsGrant->setScopeRepository($internalScopesRepo); // Change repository after enabling $clientCredentialsGrant->setScopeRepository($internalScopesRepo); // Change repository after enabling
// TODO: provide verification url
$deviceCodeGrant = new DeviceCodeGrant($deviceCodesRepo, $refreshTokensRepo, new DateInterval('PT2M'), '');
$authServer->enableGrantType($deviceCodeGrant, $accessTokenTTL);
$deviceCodeGrant->setScopeRepository($publicScopesRepo); // Change repository after enabling
return $authServer; return $authServer;
} }

View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace common\components\OAuth2\Entities;
use League\OAuth2\Server\Entities\DeviceCodeEntityInterface;
use League\OAuth2\Server\Entities\Traits\DeviceCodeTrait;
use League\OAuth2\Server\Entities\Traits\EntityTrait;
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
final class DeviceCodeEntity implements DeviceCodeEntityInterface {
use EntityTrait;
use TokenEntityTrait;
use DeviceCodeTrait;
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace common\components\OAuth2\Repositories;
use common\components\OAuth2\Entities\DeviceCodeEntity;
use League\OAuth2\Server\Entities\DeviceCodeEntityInterface;
use League\OAuth2\Server\Repositories\DeviceCodeRepositoryInterface;
final class DeviceCodeRepository implements DeviceCodeRepositoryInterface {
public function getNewDeviceCode(): DeviceCodeEntityInterface {
return new DeviceCodeEntity();
}
public function persistDeviceCode(DeviceCodeEntityInterface $deviceCodeEntity): void {
// TODO: Implement persistDeviceCode() method.
}
public function getDeviceCodeEntityByDeviceCode(string $deviceCodeEntity): ?DeviceCodeEntityInterface {
// TODO: Implement getDeviceCodeEntityByDeviceCode() method.
}
public function revokeDeviceCode(string $codeId): void {
// TODO: Implement revokeDeviceCode() method.
}
public function isDeviceCodeRevoked(string $codeId): bool {
// TODO: Implement isDeviceCodeRevoked() method.
}
}

View File

@@ -1,14 +0,0 @@
<?php
namespace common\models\amqp;
use yii\base\BaseObject;
class AccountBanned extends BaseObject {
public $accountId;
public $duration = -1;
public $message = '';
}

View File

@@ -1,10 +0,0 @@
<?php
namespace common\models\amqp;
use yii\base\BaseObject;
class AccountPardoned extends BaseObject {
public $accountId;
}

View File

@@ -1,14 +0,0 @@
<?php
namespace common\models\amqp;
use yii\base\BaseObject;
class EmailChanged extends BaseObject {
public $accountId;
public $oldEmail;
public $newEmail;
}

View File

@@ -1,14 +0,0 @@
<?php
namespace common\models\amqp;
use yii\base\BaseObject;
class UsernameChanged extends BaseObject {
public $accountId;
public $oldUsername;
public $newUsername;
}