Updated Index and RPCii.
This commit is contained in:
parent
bf40942e72
commit
a53085e447
36 changed files with 307 additions and 454 deletions
composer.jsoncomposer.lock
database
2024_07_20_185612_apps_tables.php2024_07_20_185921_oauth_tables.php2024_07_27_025524_configurable_refresh_lifetime.php2024_07_27_201438_nine_character_device_user_code.php2024_07_30_001441_removed_device_attempts_field.php2024_07_30_211859_remove_state_fields_from_authorisations_db.php2024_09_03_201657_scope_tables.php2024_09_04_205008_access_lifetime_field_for_apps_table.php
hanyuu.phpsrc
Apps
HanyuuContext.phpMisuzuRpcClient.phpOAuth2
OAuth2AccessInfo.phpOAuth2ApiRoutes.phpOAuth2AuthorisationData.phpOAuth2AuthorisationInfo.phpOAuth2Context.phpOAuth2DeviceInfo.phpOAuth2DevicesData.phpOAuth2RefreshInfo.phpOAuth2RpcHandler.phpOAuth2TokensData.phpOAuth2WebRoutes.php
RoutingContext.phpRoutingErrorHandler.phpSiteInfo.phpTemplatingExtension.phptools
|
@ -1,15 +1,13 @@
|
|||
{
|
||||
"require": {
|
||||
"flashwave/index": "^0.2408.40014",
|
||||
"flashwave/sasae": "^1.1",
|
||||
"flashwave/syokuhou": "^1.2",
|
||||
"flashwave/index": "^0.2410",
|
||||
"flashii/rpcii": "^2.0",
|
||||
"chillerlan/php-qrcode": "^4.3",
|
||||
"symfony/mailer": "^6.0",
|
||||
"matomo/device-detector": "^6.1",
|
||||
"sentry/sdk": "^4.0",
|
||||
"phpseclib/phpseclib": "~3.0",
|
||||
"nesbot/carbon": "^3.7",
|
||||
"flashwave/aiwass": "^1.0"
|
||||
"nesbot/carbon": "^3.7"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
|
|
475
composer.lock
generated
475
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class AppsTables_20240720_185612 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class AppsTables_20240720_185612 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute(<<<SQL
|
||||
CREATE TABLE hau_apps (
|
||||
app_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class OauthTables_20240720_185921 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class OauthTables_20240720_185921 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute(<<<SQL
|
||||
CREATE TABLE hau_oauth2_authorise (
|
||||
auth_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class ConfigurableRefreshLifetime_20240727_025524 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class ConfigurableRefreshLifetime_20240727_025524 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute('ALTER TABLE hau_apps ADD COLUMN app_refresh_lifetime INT UNSIGNED NULL DEFAULT NULL AFTER app_type');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class NineCharacterDeviceUserCode_20240727_201438 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class NineCharacterDeviceUserCode_20240727_201438 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute('ALTER TABLE hau_oauth2_device CHANGE COLUMN dev_user_code dev_user_code CHAR(9) NOT NULL COLLATE ascii_general_ci AFTER dev_code');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class RemovedDeviceAttemptsField_20240730_001441 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class RemovedDeviceAttemptsField_20240730_001441 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute('ALTER TABLE hau_oauth2_device DROP COLUMN dev_attempts');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class RemoveStateFieldsFromAuthorisationsDb_20240730_211859 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class RemoveStateFieldsFromAuthorisationsDb_20240730_211859 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute('ALTER TABLE hau_oauth2_authorise DROP COLUMN auth_state, DROP COLUMN auth_approval;');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class ScopeTables_20240903_201657 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class ScopeTables_20240903_201657 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute(<<<SQL
|
||||
CREATE TABLE hau_scopes (
|
||||
scope_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class AccessLifetimeFieldForAppsTable_20240904_205008 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
final class AccessLifetimeFieldForAppsTable_20240904_205008 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute(<<<SQL
|
||||
ALTER TABLE hau_apps
|
||||
ADD COLUMN app_access_lifetime INT(10) UNSIGNED NULL DEFAULT NULL AFTER app_type;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
namespace Hanyuu;
|
||||
|
||||
use Index\Data\DbTools;
|
||||
use Syokuhou\SharpConfig;
|
||||
use Index\Db\DbBackends;
|
||||
use Index\Config\Fs\FsConfig;
|
||||
|
||||
define('HAU_STARTUP', microtime(true));
|
||||
define('HAU_ROOT', __DIR__);
|
||||
|
@ -20,7 +20,7 @@ error_reporting(HAU_DEBUG ? -1 : 0);
|
|||
mb_internal_encoding('UTF-8');
|
||||
date_default_timezone_set('GMT');
|
||||
|
||||
$cfg = SharpConfig::fromFile(HAU_ROOT . '/hanyuu.cfg');
|
||||
$cfg = FsConfig::fromFile(HAU_ROOT . '/hanyuu.cfg');
|
||||
|
||||
if($cfg->hasValues('sentry:dsn'))
|
||||
(function($cfg) {
|
||||
|
@ -35,7 +35,7 @@ if($cfg->hasValues('sentry:dsn'))
|
|||
});
|
||||
})($cfg->scopeTo('sentry'));
|
||||
|
||||
$dbc = DbTools::create($cfg->getString('database:dsn', 'null'));
|
||||
$dbc = DbBackends::create($cfg->getString('database:dsn', 'null'));
|
||||
$dbc->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';');
|
||||
|
||||
$hau = new HanyuuContext($cfg, $dbc);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Hanyuu\Apps;
|
||||
|
||||
use Index\Data\IDbResult;
|
||||
use Index\Db\DbResult;
|
||||
|
||||
class AppInfo {
|
||||
public function __construct(
|
||||
|
@ -20,7 +20,7 @@ class AppInfo {
|
|||
private ?int $deleted
|
||||
) {}
|
||||
|
||||
public static function fromResult(IDbResult $result): AppInfo {
|
||||
public static function fromResult(DbResult $result): AppInfo {
|
||||
return new AppInfo(
|
||||
id: $result->getString(0),
|
||||
name: $result->getString(1),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Hanyuu\Apps;
|
||||
|
||||
use Index\Data\IDbResult;
|
||||
use Index\Db\DbResult;
|
||||
|
||||
class AppUriInfo {
|
||||
public function __construct(
|
||||
|
@ -11,7 +11,7 @@ class AppUriInfo {
|
|||
private int $created
|
||||
) {}
|
||||
|
||||
public static function fromResult(IDbResult $result): AppUriInfo {
|
||||
public static function fromResult(DbResult $result): AppUriInfo {
|
||||
return new AppUriInfo(
|
||||
id: $result->getString(0),
|
||||
appId: $result->getString(1),
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
namespace Hanyuu\Apps;
|
||||
|
||||
use RuntimeException;
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Db\DbConnection;
|
||||
|
||||
class AppsContext {
|
||||
private AppsData $apps;
|
||||
private ScopesData $scopes;
|
||||
|
||||
public function __construct(IDbConnection $dbConn) {
|
||||
public function __construct(DbConnection $dbConn) {
|
||||
$this->apps = new AppsData($dbConn);
|
||||
$this->scopes = new ScopesData($dbConn);
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ use stdClass;
|
|||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\XString;
|
||||
use Index\Data\{DbStatementCache,IDbConnection};
|
||||
use Index\Db\{DbConnection,DbStatementCache};
|
||||
|
||||
class AppsData {
|
||||
private DbStatementCache $cache;
|
||||
|
||||
public function __construct(
|
||||
private IDbConnection $dbConn
|
||||
private DbConnection $dbConn
|
||||
) {
|
||||
$this->cache = new DbStatementCache($dbConn);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Hanyuu\Apps;
|
||||
|
||||
use Index\Data\IDbResult;
|
||||
use Index\Db\DbResult;
|
||||
|
||||
class ScopeInfo {
|
||||
public function __construct(
|
||||
|
@ -13,7 +13,7 @@ class ScopeInfo {
|
|||
private ?int $deprecated
|
||||
) {}
|
||||
|
||||
public static function fromResult(IDbResult $result): ScopeInfo {
|
||||
public static function fromResult(DbResult $result): ScopeInfo {
|
||||
return new ScopeInfo(
|
||||
$result->getString(0),
|
||||
$result->getString(1),
|
||||
|
|
|
@ -3,13 +3,13 @@ namespace Hanyuu\Apps;
|
|||
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\Data\{DbStatementCache,IDbConnection};
|
||||
use Index\Db\{DbConnection,DbStatementCache};
|
||||
|
||||
class ScopesData {
|
||||
private DbStatementCache $cache;
|
||||
|
||||
public function __construct(
|
||||
private IDbConnection $dbConn
|
||||
private DbConnection $dbConn
|
||||
) {
|
||||
$this->cache = new DbStatementCache($dbConn);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
<?php
|
||||
namespace Hanyuu;
|
||||
|
||||
use Aiwass\HmacVerificationProvider;
|
||||
use Aiwass\Server\RpcServer;
|
||||
use Index\Environment;
|
||||
use Index\Colour\Colour;
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\{IDbMigrationRepo,DbMigrationManager,FsDbMigrationRepo};
|
||||
use Sasae\SasaeEnvironment;
|
||||
use Syokuhou\IConfig;
|
||||
use Index\Config\Config;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\{DbMigrationRepo,DbMigrationManager,FsDbMigrationRepo};
|
||||
use Index\Templating\TplEnvironment;
|
||||
use RPCii\HmacVerificationProvider;
|
||||
use RPCii\Server\HttpRpcServer;
|
||||
|
||||
class HanyuuContext {
|
||||
private IConfig $config;
|
||||
private IDbConnection $dbConn;
|
||||
private SasaeEnvironment $templating;
|
||||
private Config $config;
|
||||
private DbConnection $dbConn;
|
||||
private TplEnvironment $templating;
|
||||
private SiteInfo $siteInfo;
|
||||
|
||||
private MisuzuRpcClient $misuzuRpc;
|
||||
|
@ -22,7 +21,7 @@ class HanyuuContext {
|
|||
private Apps\AppsContext $appsCtx;
|
||||
private OAuth2\OAuth2Context $oauth2Ctx;
|
||||
|
||||
public function __construct(IConfig $config, IDbConnection $dbConn) {
|
||||
public function __construct(Config $config, DbConnection $dbConn) {
|
||||
$this->config = $config;
|
||||
$this->dbConn = $dbConn;
|
||||
$this->siteInfo = new SiteInfo($config->scopeTo('site'));
|
||||
|
@ -35,12 +34,12 @@ class HanyuuContext {
|
|||
$this->appsCtx
|
||||
);
|
||||
|
||||
$this->templating = new SasaeEnvironment(
|
||||
$this->templating = new TplEnvironment(
|
||||
HAU_DIR_TEMPLATES,
|
||||
cache: null,//HAU_DEBUG ? null : ['Hanyuu', GitInfo::hash(true)],
|
||||
debug: HAU_DEBUG,
|
||||
);
|
||||
$this->templating->addExtension(new HanyuuSasaeExtension($this));
|
||||
$this->templating->addExtension(new TemplatingExtension($this));
|
||||
|
||||
$this->templating->addGlobal('globals', [
|
||||
'siteInfo' => $this->siteInfo,
|
||||
|
@ -51,7 +50,7 @@ class HanyuuContext {
|
|||
return $this->misuzuRpc;
|
||||
}
|
||||
|
||||
public function getDatabase(): IDbConnection {
|
||||
public function getDatabase(): DbConnection {
|
||||
return $this->dbConn;
|
||||
}
|
||||
|
||||
|
@ -64,7 +63,7 @@ class HanyuuContext {
|
|||
return new DbMigrationManager($this->dbConn, 'hau_' . DbMigrationManager::DEFAULT_TABLE);
|
||||
}
|
||||
|
||||
public function createMigrationRepo(): IDbMigrationRepo {
|
||||
public function createMigrationRepo(): DbMigrationRepo {
|
||||
return new FsDbMigrationRepo(HAU_DIR_MIGRATIONS);
|
||||
}
|
||||
|
||||
|
@ -77,7 +76,7 @@ class HanyuuContext {
|
|||
return $this->authInfo;
|
||||
}
|
||||
|
||||
public function getCSRFPSecret(): string {
|
||||
public function getCsrfTokenSecret(): string {
|
||||
return $this->config->getString('csrfp:secret', 'beans');
|
||||
}
|
||||
|
||||
|
@ -86,7 +85,7 @@ class HanyuuContext {
|
|||
return is_file($path) ? json_decode(file_get_contents($path)) : null;
|
||||
}
|
||||
|
||||
public function getTemplating(): SasaeEnvironment {
|
||||
public function getTemplating(): TplEnvironment {
|
||||
return $this->templating;
|
||||
}
|
||||
|
||||
|
@ -111,15 +110,15 @@ class HanyuuContext {
|
|||
$this->oauth2Ctx,
|
||||
$this->templating,
|
||||
$this->getAuthInfo(...),
|
||||
$this->getCSRFPSecret(...)
|
||||
$this->getCsrfTokenSecret(...)
|
||||
));
|
||||
|
||||
$rpcServer = new RpcServer;
|
||||
$rpcServer = new HttpRpcServer;
|
||||
$routingCtx->register($rpcServer->createRouteHandler(
|
||||
new HmacVerificationProvider(fn() => $this->config->getString('aleister:secret'))
|
||||
));
|
||||
|
||||
$rpcServer->register(new OAuth2\OAuth2RpcActions($this->oauth2Ctx));
|
||||
$rpcServer->register(new OAuth2\OAuth2RpcHandler($this->oauth2Ctx));
|
||||
|
||||
return $routingCtx;
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@ namespace Hanyuu;
|
|||
|
||||
use stdClass;
|
||||
use RuntimeException;
|
||||
use Aiwass\Client\RpcClient;
|
||||
use Index\UriBase64;
|
||||
use Syokuhou\IConfig;
|
||||
use Index\Config\Config;
|
||||
use RPCii\Client\{HttpRpcClient,RpcClient};
|
||||
|
||||
class MisuzuRpcClient {
|
||||
private RpcClient $client;
|
||||
|
||||
public function __construct(IConfig $config) {
|
||||
$this->client = RpcClient::createHmac(
|
||||
public function __construct(Config $config) {
|
||||
$this->client = HttpRpcClient::createHmac(
|
||||
sprintf('%s/_hanyuu', $config->getString('endpoint')),
|
||||
fn() => $config->getString('secret')
|
||||
);
|
||||
|
@ -22,7 +22,7 @@ class MisuzuRpcClient {
|
|||
}
|
||||
|
||||
public function authCheck(string $method, string $token, string $remoteAddr, array $avatars = []): MisuzuAuthInfo {
|
||||
$result = $this->client->procedure('mszhau:authCheck', [
|
||||
$result = $this->client->action('mszhau:authCheck', [
|
||||
'method' => $method,
|
||||
'token' => $token,
|
||||
'remoteAddr' => $remoteAddr,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Hanyuu\OAuth2;
|
||||
|
||||
use Index\Data\IDbResult;
|
||||
use Index\Db\DbResult;
|
||||
|
||||
class OAuth2AccessInfo {
|
||||
public const DEFAULT_LIFETIME = 3600;
|
||||
|
@ -16,7 +16,7 @@ class OAuth2AccessInfo {
|
|||
private int $expires
|
||||
) {}
|
||||
|
||||
public static function fromResult(IDbResult $result): OAuth2AccessInfo {
|
||||
public static function fromResult(DbResult $result): OAuth2AccessInfo {
|
||||
return new OAuth2AccessInfo(
|
||||
id: $result->getString(0),
|
||||
appId: $result->getString(1),
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
namespace Hanyuu\OAuth2;
|
||||
|
||||
use RuntimeException;
|
||||
use Index\Http\Routing\{HttpGet,HttpOptions,HttpPost,RouteHandler};
|
||||
use Syokuhou\IConfig;
|
||||
use Index\Http\Routing\{HttpGet,HttpOptions,HttpPost,RouteHandler,RouteHandlerTrait};
|
||||
|
||||
final class OAuth2ApiRoutes implements RouteHandler {
|
||||
use RouteHandlerTrait;
|
||||
|
||||
final class OAuth2ApiRoutes extends RouteHandler {
|
||||
public function __construct(
|
||||
private OAuth2Context $oauth2Ctx
|
||||
) {}
|
||||
|
|
|
@ -4,16 +4,15 @@ namespace Hanyuu\OAuth2;
|
|||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\XString;
|
||||
use Index\Data\DbStatementCache;
|
||||
use Index\Data\IDbConnection;
|
||||
use Hanyuu\Apps\AppInfo;
|
||||
use Hanyuu\Apps\AppUriInfo;
|
||||
use Index\Db\{DbConnection,DbStatementCache};
|
||||
use Hanyuu\Apps\{AppInfo,AppUriInfo};
|
||||
|
||||
class OAuth2AuthorisationData {
|
||||
private IDbConnection $dbConn;
|
||||
private DbStatementCache $cache;
|
||||
|
||||
public function __construct(IDbConnection $dbConn) {
|
||||
public function __construct(
|
||||
private DbConnection $dbConn
|
||||
) {
|
||||
$this->dbConn = $dbConn;
|
||||
$this->cache = new DbStatementCache($dbConn);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
namespace Hanyuu\OAuth2;
|
||||
|
||||
use Index\UriBase64;
|
||||
use Index\Data\IDbResult;
|
||||
use Index\Db\DbResult;
|
||||
|
||||
class OAuth2AuthorisationInfo {
|
||||
public function __construct(
|
||||
|
@ -18,7 +18,7 @@ class OAuth2AuthorisationInfo {
|
|||
private int $expires
|
||||
) {}
|
||||
|
||||
public static function fromResult(IDbResult $result): OAuth2AuthorisationInfo {
|
||||
public static function fromResult(DbResult $result): OAuth2AuthorisationInfo {
|
||||
return new OAuth2AuthorisationInfo(
|
||||
id: $result->getString(0),
|
||||
appId: $result->getString(1),
|
||||
|
|
|
@ -3,8 +3,8 @@ namespace Hanyuu\OAuth2;
|
|||
|
||||
use RuntimeException;
|
||||
use Hanyuu\Apps\{AppsContext,AppInfo};
|
||||
use Index\Data\IDbConnection;
|
||||
use Syokuhou\IConfig;
|
||||
use Index\Config\Config;
|
||||
use Index\Db\DbConnection;
|
||||
|
||||
class OAuth2Context {
|
||||
private OAuth2AuthorisationData $authorisations;
|
||||
|
@ -12,8 +12,8 @@ class OAuth2Context {
|
|||
private OAuth2DevicesData $devices;
|
||||
|
||||
public function __construct(
|
||||
private IConfig $config,
|
||||
IDbConnection $dbConn,
|
||||
private Config $config,
|
||||
DbConnection $dbConn,
|
||||
private AppsContext $appsCtx
|
||||
) {
|
||||
$this->authorisations = new OAuth2AuthorisationData($dbConn);
|
||||
|
@ -21,7 +21,7 @@ class OAuth2Context {
|
|||
$this->devices = new OAuth2DevicesData($dbConn);
|
||||
}
|
||||
|
||||
public function getConfig(): IConfig {
|
||||
public function getConfig(): Config {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Hanyuu\OAuth2;
|
||||
|
||||
use Index\Data\IDbResult;
|
||||
use Index\Db\DbResult;
|
||||
|
||||
class OAuth2DeviceInfo {
|
||||
public const DEFAULT_LIFETIME = 600;
|
||||
|
@ -21,7 +21,7 @@ class OAuth2DeviceInfo {
|
|||
private int $expires
|
||||
) {}
|
||||
|
||||
public static function fromResult(IDbResult $result): OAuth2DeviceInfo {
|
||||
public static function fromResult(DbResult $result): OAuth2DeviceInfo {
|
||||
return new OAuth2DeviceInfo(
|
||||
id: $result->getString(0),
|
||||
appId: $result->getString(1),
|
||||
|
|
|
@ -4,8 +4,7 @@ namespace Hanyuu\OAuth2;
|
|||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\XString;
|
||||
use Index\Data\DbStatementCache;
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Db\{DbConnection,DbStatementCache};
|
||||
use Hanyuu\Apps\AppInfo;
|
||||
|
||||
class OAuth2DevicesData {
|
||||
|
@ -14,7 +13,7 @@ class OAuth2DevicesData {
|
|||
private DbStatementCache $cache;
|
||||
|
||||
public function __construct(
|
||||
private IDbConnection $dbConn
|
||||
private DbConnection $dbConn
|
||||
) {
|
||||
$this->cache = new DbStatementCache($dbConn);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Hanyuu\OAuth2;
|
||||
|
||||
use Index\Data\IDbResult;
|
||||
use Index\Db\DbResult;
|
||||
|
||||
class OAuth2RefreshInfo {
|
||||
public function __construct(
|
||||
|
@ -15,7 +15,7 @@ class OAuth2RefreshInfo {
|
|||
private int $expires
|
||||
) {}
|
||||
|
||||
public static function fromResult(IDbResult $result): OAuth2RefreshInfo {
|
||||
public static function fromResult(DbResult $result): OAuth2RefreshInfo {
|
||||
return new OAuth2RefreshInfo(
|
||||
id: $result->getString(0),
|
||||
appId: $result->getString(1),
|
||||
|
|
|
@ -3,10 +3,11 @@ namespace Hanyuu\OAuth2;
|
|||
|
||||
use RuntimeException;
|
||||
use Hanyuu\Apps\AppsContext;
|
||||
use Aiwass\Server\{RpcActionHandler,RpcProcedure};
|
||||
use Syokuhou\IConfig;
|
||||
use RPCii\Server\{RpcHandler,RpcHandlerCommon,RpcAction};
|
||||
|
||||
final class OAuth2RpcHandler implements RpcHandler {
|
||||
use RpcHandlerCommon;
|
||||
|
||||
final class OAuth2RpcActions extends RpcActionHandler {
|
||||
public function __construct(
|
||||
private OAuth2Context $oauth2Ctx
|
||||
) {}
|
||||
|
@ -26,7 +27,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
return $scopes;
|
||||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:attemptAppAuth')]
|
||||
#[RpcAction('hanyuu:oauth2:attemptAppAuth')]
|
||||
public function procAttemptAppAuth(string $remoteAddr, string $clientId, string $clientSecret = ''): array {
|
||||
try {
|
||||
$appInfo = $this->oauth2Ctx->getApps()->getAppsData()->getAppInfo(clientId: $clientId, deleted: false);
|
||||
|
@ -52,7 +53,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
];
|
||||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:attemptBearerAuth')]
|
||||
#[RpcAction('hanyuu:oauth2:attemptBearerAuth')]
|
||||
public function procAttemptBearerAuth(string $remoteAddr, string $token): array {
|
||||
try {
|
||||
$tokenInfo = $this->oauth2Ctx->getTokensData()->getAccessInfo($token, OAuth2TokensData::ACCESS_BY_TOKEN);
|
||||
|
@ -73,7 +74,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
];
|
||||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:createAuthoriseRequest')]
|
||||
#[RpcAction('hanyuu:oauth2:createAuthoriseRequest')]
|
||||
public function procCreateAuthoriseRequest(string $appId, ?string $scope = null): array {
|
||||
try {
|
||||
$appInfo = $this->oauth2Ctx->getApps()->getAppsData()->getAppInfo(appId: $appId, deleted: false);
|
||||
|
@ -87,7 +88,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
return $this->oauth2Ctx->createDeviceAuthorisationRequest($appInfo, $scope);
|
||||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:createBearerToken:authorisationCode')]
|
||||
#[RpcAction('hanyuu:oauth2:createBearerToken:authorisationCode')]
|
||||
public function procCreateBearerTokenAuthzCode(string $appId, bool $isAuthed, string $code, string $codeVerifier): array {
|
||||
try {
|
||||
$appInfo = $this->oauth2Ctx->getApps()->getAppsData()->getAppInfo(appId: $appId, deleted: false);
|
||||
|
@ -101,7 +102,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
return $this->oauth2Ctx->redeemAuthorisationCode($appInfo, $isAuthed, $code, $codeVerifier);
|
||||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:createBearerToken:refreshToken')]
|
||||
#[RpcAction('hanyuu:oauth2:createBearerToken:refreshToken')]
|
||||
public function procCreateBearerTokenRefreshToken(string $appId, bool $isAuthed, string $refreshToken, ?string $scope = null): array {
|
||||
try {
|
||||
$appInfo = $this->oauth2Ctx->getApps()->getAppsData()->getAppInfo(appId: $appId, deleted: false);
|
||||
|
@ -115,7 +116,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
return $this->oauth2Ctx->redeemRefreshToken($appInfo, $isAuthed, $refreshToken, $scope);
|
||||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:createBearerToken:clientCredentials')]
|
||||
#[RpcAction('hanyuu:oauth2:createBearerToken:clientCredentials')]
|
||||
public function procCreateBearerTokenClientCreds(string $appId, bool $isAuthed, ?string $scope = null): array {
|
||||
try {
|
||||
$appInfo = $this->oauth2Ctx->getApps()->getAppsData()->getAppInfo(appId: $appId, deleted: false);
|
||||
|
@ -129,7 +130,7 @@ final class OAuth2RpcActions extends RpcActionHandler {
|
|||
return $this->oauth2Ctx->redeemClientCredentials($appInfo, $isAuthed, $scope);
|
||||
}
|
||||
|
||||
#[RpcProcedure('hanyuu:oauth2:createBearerToken:deviceCode')]
|
||||
#[RpcAction('hanyuu:oauth2:createBearerToken:deviceCode')]
|
||||
public function procCreateBearerTokenDeviceCode(string $appId, bool $isAuthed, string $deviceCode): array {
|
||||
try {
|
||||
$appInfo = $this->oauth2Ctx->getApps()->getAppsData()->getAppInfo(appId: $appId, deleted: false);
|
|
@ -4,15 +4,14 @@ namespace Hanyuu\OAuth2;
|
|||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\XString;
|
||||
use Index\Data\DbStatementCache;
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Db\{DbConnection,DbStatementCache};
|
||||
use Hanyuu\Apps\AppInfo;
|
||||
|
||||
class OAuth2TokensData {
|
||||
private DbStatementCache $cache;
|
||||
|
||||
public function __construct(
|
||||
private IDbConnection $dbConn
|
||||
private DbConnection $dbConn
|
||||
) {
|
||||
$this->cache = new DbStatementCache($dbConn);
|
||||
}
|
||||
|
|
|
@ -3,22 +3,23 @@ namespace Hanyuu\OAuth2;
|
|||
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Index\CSRFP;
|
||||
use Index\Http\Routing\{HttpGet,HttpPost,RouteHandler};
|
||||
use Sasae\SasaeEnvironment;
|
||||
use Syokuhou\IConfig;
|
||||
use Index\CsrfToken;
|
||||
use Index\Http\Routing\{HttpGet,HttpPost,RouteHandler,RouteHandlerTrait};
|
||||
use Index\Templating\TplEnvironment;
|
||||
|
||||
final class OAuth2WebRoutes implements RouteHandler {
|
||||
use RouteHandlerTrait;
|
||||
|
||||
final class OAuth2WebRoutes extends RouteHandler {
|
||||
public function __construct(
|
||||
private OAuth2Context $oauth2Ctx,
|
||||
private SasaeEnvironment $templating,
|
||||
private TplEnvironment $templating,
|
||||
private $getAuthInfo,
|
||||
private $getCSRFPSecret
|
||||
private $getCsrfTokenSecret
|
||||
) {
|
||||
if(!is_callable($getAuthInfo))
|
||||
throw new InvalidArgumentException('$getAuthInfo must be callable');
|
||||
if(!is_callable($getCSRFPSecret))
|
||||
throw new InvalidArgumentException('$getCSRFPSecret must be callable');
|
||||
if(!is_callable($getCsrfTokenSecret))
|
||||
throw new InvalidArgumentException('$getCsrfTokenSecret must be callable');
|
||||
}
|
||||
|
||||
#[HttpGet('/oauth2/authorise')]
|
||||
|
@ -30,7 +31,7 @@ final class OAuth2WebRoutes extends RouteHandler {
|
|||
'register_url' => $authInfo->getRegisterUrl(),
|
||||
]);
|
||||
|
||||
$csrfp = new CSRFP(($this->getCSRFPSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
$csrfp = new CsrfToken(($this->getCsrfTokenSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
|
||||
return $this->templating->render('oauth2/authorise', [
|
||||
'csrfp_token' => $csrfp->createToken(),
|
||||
|
@ -50,7 +51,7 @@ final class OAuth2WebRoutes extends RouteHandler {
|
|||
|
||||
$content = $request->getContent();
|
||||
|
||||
$csrfp = new CSRFP(($this->getCSRFPSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
$csrfp = new CsrfToken(($this->getCsrfTokenSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
if(!$csrfp->verifyToken((string)$content->getParam('_csrfp')))
|
||||
return ['error' => 'csrf'];
|
||||
|
||||
|
@ -137,7 +138,7 @@ final class OAuth2WebRoutes extends RouteHandler {
|
|||
return ['error' => 'auth'];
|
||||
|
||||
$sessionInfo = $authInfo->getSessionInfo();
|
||||
$csrfp = new CSRFP(($this->getCSRFPSecret)(), $sessionInfo->getToken());
|
||||
$csrfp = new CsrfToken(($this->getCsrfTokenSecret)(), $sessionInfo->getToken());
|
||||
if(!$csrfp->verifyToken((string)$request->getParam('csrfp')))
|
||||
return ['error' => 'csrf'];
|
||||
|
||||
|
@ -212,7 +213,7 @@ final class OAuth2WebRoutes extends RouteHandler {
|
|||
'register_url' => $authInfo->getRegisterUrl(),
|
||||
]);
|
||||
|
||||
$csrfp = new CSRFP(($this->getCSRFPSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
$csrfp = new CsrfToken(($this->getCsrfTokenSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
|
||||
return $this->templating->render('oauth2/verify', [
|
||||
'csrfp_token' => $csrfp->createToken(),
|
||||
|
@ -232,7 +233,7 @@ final class OAuth2WebRoutes extends RouteHandler {
|
|||
|
||||
$content = $request->getContent();
|
||||
|
||||
$csrfp = new CSRFP(($this->getCSRFPSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
$csrfp = new CsrfToken(($this->getCsrfTokenSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
if(!$csrfp->verifyToken((string)$content->getParam('_csrfp')))
|
||||
return ['error' => 'csrf'];
|
||||
|
||||
|
@ -294,7 +295,7 @@ final class OAuth2WebRoutes extends RouteHandler {
|
|||
if($authInfo->isFailure())
|
||||
return ['error' => 'auth'];
|
||||
|
||||
$csrfp = new CSRFP(($this->getCSRFPSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
$csrfp = new CsrfToken(($this->getCsrfTokenSecret)(), $authInfo->getSessionInfo()->getToken());
|
||||
if(!$csrfp->verifyToken((string)$request->getParam('csrfp')))
|
||||
return ['error' => 'csrf'];
|
||||
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
<?php
|
||||
namespace Hanyuu;
|
||||
|
||||
use Index\Http\Routing\{HttpRouter,IRouter,IRouteHandler};
|
||||
use Sasae\SasaeEnvironment;
|
||||
use Index\Http\Routing\{HttpRouter,Router,RouteHandler};
|
||||
use Index\Templating\TplEnvironment;
|
||||
|
||||
class RoutingContext {
|
||||
private HttpRouter $router;
|
||||
private SasaeEnvironment $templating;
|
||||
private TplEnvironment $templating;
|
||||
|
||||
public function __construct(SasaeEnvironment $templating) {
|
||||
public function __construct(TplEnvironment $templating) {
|
||||
$this->templating = $templating;
|
||||
$this->router = new HttpRouter(errorHandler: new RoutingErrorHandler);
|
||||
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Hanyuu'));
|
||||
}
|
||||
|
||||
public function getRouter(): IRouter {
|
||||
public function getRouter(): Router {
|
||||
return $this->router;
|
||||
}
|
||||
|
||||
public function register(IRouteHandler $handler): void {
|
||||
public function register(RouteHandler $handler): void {
|
||||
$this->router->register($handler);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
namespace Hanyuu;
|
||||
|
||||
use Index\Http\{HttpResponseBuilder,HttpRequest};
|
||||
use Index\Http\ErrorHandling\HtmlErrorHandler;
|
||||
use Index\Http\{HtmlHttpErrorHandler,HttpResponseBuilder,HttpRequest};
|
||||
|
||||
class RoutingErrorHandler extends HtmlErrorHandler {
|
||||
class RoutingErrorHandler extends HtmlHttpErrorHandler {
|
||||
#[\Override]
|
||||
public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void {
|
||||
$path = HAU_DIR_PUBLIC . sprintf('/error-%03d.html', $code);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
namespace Hanyuu;
|
||||
|
||||
use Syokuhou\IConfig;
|
||||
use Index\Config\Config;
|
||||
|
||||
class SiteInfo {
|
||||
public function __construct(
|
||||
private IConfig $config
|
||||
private Config $config
|
||||
) {}
|
||||
|
||||
public function getName(): string {
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Hanyuu;
|
|||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
final class HanyuuSasaeExtension extends AbstractExtension {
|
||||
final class TemplatingExtension extends AbstractExtension {
|
||||
private HanyuuContext $ctx;
|
||||
private ?object $assets;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
use Index\Data\Migration\FsDbMigrationRepo;
|
||||
use Index\Db\Migration\FsDbMigrationRepo;
|
||||
|
||||
require_once __DIR__ . '/../hanyuu.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
use Index\Data\Migration\FsDbMigrationRepo;
|
||||
use Index\Db\Migration\FsDbMigrationRepo;
|
||||
|
||||
require_once __DIR__ . '/../hanyuu.php';
|
||||
|
||||
|
|
Loading…
Reference in a new issue