2022-01-25 12:17:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OAuth2 Client
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
*
|
|
|
|
* @author Hugo Sales <hugo@hsal.es>
|
|
|
|
* @copyright 2022 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Plugin\OAuth2\Entity;
|
|
|
|
|
|
|
|
use App\Core\Entity;
|
|
|
|
use DateTimeInterface;
|
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface;
|
|
|
|
|
|
|
|
class Client extends Entity implements ClientEntityInterface
|
|
|
|
{
|
|
|
|
// {{{ Autocode
|
|
|
|
// @codeCoverageIgnoreStart
|
|
|
|
private string $id;
|
|
|
|
private string $secret;
|
|
|
|
private bool $active;
|
|
|
|
private bool $plain_pcke;
|
|
|
|
private bool $is_confidential;
|
|
|
|
private string $redirect_uris;
|
|
|
|
private string $grants;
|
|
|
|
private string $scopes;
|
|
|
|
private string $client_name;
|
|
|
|
private ?string $website = null;
|
|
|
|
private DateTimeInterface $created;
|
|
|
|
private DateTimeInterface $modified;
|
|
|
|
|
|
|
|
public function setId(string $id): self
|
|
|
|
{
|
|
|
|
$this->id = mb_substr($id, 0, 64);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getId(): string
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->id;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setSecret(string $secret): self
|
|
|
|
{
|
|
|
|
$this->secret = mb_substr($secret, 0, 64);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getSecret(): string
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->secret;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setActive(bool $active): self
|
|
|
|
{
|
|
|
|
$this->active = $active;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getActive(): bool
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->active;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setPlainPcke(bool $plain_pcke): self
|
|
|
|
{
|
|
|
|
$this->plain_pcke = $plain_pcke;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getPlainPcke(): bool
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->plain_pcke;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setIsConfidential(bool $is_confidential): self
|
|
|
|
{
|
|
|
|
$this->is_confidential = $is_confidential;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getIsConfidential(): bool
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->is_confidential;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setRedirectUris(string $redirect_uris): self
|
|
|
|
{
|
|
|
|
$this->redirect_uris = $redirect_uris;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getRedirectUris(): string
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->redirect_uris;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setGrants(string $grants): self
|
|
|
|
{
|
|
|
|
$this->grants = $grants;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getGrants(): string
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->grants;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setScopes(string $scopes): self
|
|
|
|
{
|
|
|
|
$this->scopes = $scopes;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getScopes(): string
|
|
|
|
{
|
|
|
|
return $this->scopes;
|
|
|
|
}
|
|
|
|
|
2022-01-25 12:17:32 +00:00
|
|
|
public function setClientName(string $client_name): self
|
|
|
|
{
|
|
|
|
$this->client_name = mb_substr($client_name, 0, 191);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClientName(): string
|
|
|
|
{
|
|
|
|
return $this->client_name;
|
|
|
|
}
|
|
|
|
|
2022-02-04 18:34:08 +00:00
|
|
|
public function setWebsite(?string $website): self
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-04 18:34:08 +00:00
|
|
|
$this->website = $website;
|
2022-01-25 12:17:32 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getWebsite(): ?string
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->website;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 18:34:08 +00:00
|
|
|
public function setCreated(DateTimeInterface $created): self
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-04 18:34:08 +00:00
|
|
|
$this->created = $created;
|
2022-01-25 12:17:32 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-02-26 14:45:38 +00:00
|
|
|
public function getCreated(): DateTimeInterface
|
2022-01-25 12:17:32 +00:00
|
|
|
{
|
2022-02-26 14:45:38 +00:00
|
|
|
return $this->created;
|
2022-01-25 12:17:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 18:34:08 +00:00
|
|
|
public function setModified(DateTimeInterface $modified): self
|
|
|
|
{
|
|
|
|
$this->modified = $modified;
|
|
|
|
return $this;
|
|
|
|
}
|
2022-02-26 14:45:38 +00:00
|
|
|
|
|
|
|
public function getModified(): DateTimeInterface
|
|
|
|
{
|
|
|
|
return $this->modified;
|
|
|
|
}
|
|
|
|
|
2022-01-25 12:17:32 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
|
|
|
// }}} Autocode
|
|
|
|
|
|
|
|
public function getIdentifier()
|
|
|
|
{
|
|
|
|
return $this->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(): string
|
|
|
|
{
|
|
|
|
return $this->getClientName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRedirectUri(): string
|
|
|
|
{
|
|
|
|
return mb_substr($this->getRedirectUris(), 0, mb_strpos($this->getRedirectUris(), ' ') ?: null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isConfidential(): bool
|
|
|
|
{
|
|
|
|
return $this->getIsConfidential();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function schemaDef(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => 'oauth2_client',
|
|
|
|
'fields' => [
|
|
|
|
'id' => ['type' => 'char', 'length' => 64, 'not null' => true, 'description' => 'client identifier'],
|
|
|
|
'secret' => ['type' => 'char', 'length' => 64, 'not null' => true, 'description' => 'client secret'],
|
|
|
|
'active' => ['type' => 'bool', 'not null' => true, 'description' => 'whether this client is active'],
|
|
|
|
'plain_pcke' => ['type' => 'bool', 'not null' => true, 'description' => 'whether to allow plaintext PKCE'],
|
|
|
|
'is_confidential' => ['type' => 'bool', 'not null' => true, 'description' => 'whether this client needs to provide the secret'],
|
|
|
|
'redirect_uris' => ['type' => 'text', 'not null' => true, 'description' => 'application redirect uris, space separated'],
|
|
|
|
'grants' => ['type' => 'text', 'not null' => true, 'description' => 'application grants, space separated'],
|
|
|
|
'scopes' => ['type' => 'text', 'not null' => true, 'description' => 'application scopes, space separated'],
|
|
|
|
'client_name' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'name of the application'],
|
|
|
|
'website' => ['type' => 'text', 'not null' => false, 'description' => 'application homepage - used for source link'],
|
|
|
|
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
|
|
|
|
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
|
|
|
|
],
|
|
|
|
'primary key' => ['id'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|