mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implemented desktop application type
This commit is contained in:
@@ -9,9 +9,9 @@ use common\models\OauthClient;
|
||||
|
||||
abstract class BaseOauthClientType extends ApiForm implements OauthClientTypeForm {
|
||||
|
||||
public $name;
|
||||
public mixed $name = null;
|
||||
|
||||
public $websiteUrl;
|
||||
public mixed $websiteUrl = null;
|
||||
|
||||
public function rules(): array {
|
||||
return [
|
||||
|
||||
24
api/modules/oauth/models/DesktopApplicationType.php
Normal file
24
api/modules/oauth/models/DesktopApplicationType.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\modules\oauth\models;
|
||||
|
||||
use common\models\OauthClient;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
final class DesktopApplicationType extends BaseOauthClientType {
|
||||
|
||||
public mixed $description = null;
|
||||
|
||||
public function rules(): array {
|
||||
return ArrayHelper::merge(parent::rules(), [
|
||||
['description', 'string'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function applyToClient(OauthClient $client): void {
|
||||
parent::applyToClient($client);
|
||||
$client->description = $this->description;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,27 +6,30 @@ namespace api\modules\oauth\models;
|
||||
use api\modules\oauth\exceptions\UnsupportedOauthClientType;
|
||||
use common\models\OauthClient;
|
||||
|
||||
class OauthClientFormFactory {
|
||||
final class OauthClientFormFactory {
|
||||
|
||||
/**
|
||||
* @param OauthClient $client
|
||||
*
|
||||
* @return OauthClientTypeForm
|
||||
* @throws UnsupportedOauthClientType
|
||||
*/
|
||||
public static function create(OauthClient $client): OauthClientTypeForm {
|
||||
return match ($client->type) {
|
||||
OauthClient::TYPE_APPLICATION => new ApplicationType([
|
||||
OauthClient::TYPE_WEB_APPLICATION => new WebApplicationType([
|
||||
'name' => $client->name,
|
||||
'websiteUrl' => $client->website_url,
|
||||
'description' => $client->description,
|
||||
'redirectUri' => $client->redirect_uri,
|
||||
]),
|
||||
OauthClient::TYPE_DESKTOP_APPLICATION => new DesktopApplicationType([
|
||||
'name' => $client->name,
|
||||
'description' => $client->description,
|
||||
'websiteUrl' => $client->website_url,
|
||||
]),
|
||||
OauthClient::TYPE_MINECRAFT_SERVER => new MinecraftServerType([
|
||||
'name' => $client->name,
|
||||
'websiteUrl' => $client->website_url,
|
||||
'minecraftServerIp' => $client->minecraft_server_ip,
|
||||
]),
|
||||
// @phpstan-ignore match.unreachable (Not quite correct code, but the value comes from the user and might be not expected)
|
||||
default => throw new UnsupportedOauthClientType($client->type),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,21 +3,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace api\modules\oauth\models;
|
||||
|
||||
use Closure;
|
||||
use common\helpers\Error as E;
|
||||
use common\models\OauthClient;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
final class ApplicationType extends BaseOauthClientType {
|
||||
final class WebApplicationType extends BaseOauthClientType {
|
||||
|
||||
public $description;
|
||||
public mixed $description = null;
|
||||
|
||||
public $redirectUri;
|
||||
public mixed $redirectUri = null;
|
||||
|
||||
public function rules(): array {
|
||||
return ArrayHelper::merge(parent::rules(), [
|
||||
['redirectUri', 'required', 'message' => E::REDIRECT_URI_REQUIRED],
|
||||
['redirectUri', Closure::fromCallable([$this, 'validateUrl'])],
|
||||
['redirectUri', $this->validateUrl(...)],
|
||||
['description', 'string'],
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user