mirror of
https://github.com/webmasterskaya/joomla-oauth-server.git
synced 2024-11-23 22:34:50 +03:00
_JEXEC & copyright
This commit is contained in:
parent
f53892aac5
commit
366ddf3534
@ -1,4 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_oauthserver
|
||||
*
|
||||
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
|
||||
* @license MIT; see LICENSE.txt
|
||||
**/
|
||||
|
||||
namespace Webmasterskaya\Component\OauthServer\Site\Repository;
|
||||
|
||||
@ -10,21 +17,23 @@ use Webmasterskaya\Component\OauthServer\Administrator\Model\AccessTokenModel;
|
||||
use Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel;
|
||||
use Webmasterskaya\Component\OauthServer\Site\Entity\AccessToken;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class AccessTokenRepository implements AccessTokenRepositoryInterface
|
||||
{
|
||||
private AccessTokenModel $accessTokenModel;
|
||||
private ClientModel $clientModel;
|
||||
|
||||
/**
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\AccessTokenModel $accessTokenModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel $clientModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\AccessTokenModel $accessTokenModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel $clientModel
|
||||
*
|
||||
* @since version
|
||||
*/
|
||||
public function __construct(AccessTokenModel $accessTokenModel, ClientModel $clientModel)
|
||||
{
|
||||
$this->accessTokenModel = $accessTokenModel;
|
||||
$this->clientModel = $clientModel;
|
||||
$this->clientModel = $clientModel;
|
||||
}
|
||||
|
||||
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): AccessTokenEntityInterface
|
||||
@ -33,7 +42,8 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
|
||||
$accessToken->setClient($clientEntity);
|
||||
$accessToken->setUserIdentifier($userIdentifier);
|
||||
|
||||
foreach ($scopes as $scope) {
|
||||
foreach ($scopes as $scope)
|
||||
{
|
||||
$accessToken->addScope($scope);
|
||||
}
|
||||
|
||||
@ -43,16 +53,21 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
|
||||
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): void
|
||||
{
|
||||
$found = false;
|
||||
try {
|
||||
try
|
||||
{
|
||||
/** @var AccessToken $accessTokenEntity */
|
||||
$accessToken = $this->accessTokenModel->getItemByIdentifier($accessTokenEntity->getIdentifier());
|
||||
if ($accessToken->id > 0) {
|
||||
if ($accessToken->id > 0)
|
||||
{
|
||||
$found = true;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
if ($found)
|
||||
{
|
||||
throw UniqueTokenIdentifierConstraintViolationException::create();
|
||||
}
|
||||
|
||||
@ -76,10 +91,11 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
|
||||
{
|
||||
$accessToken = $this->accessTokenModel->getItemByIdentifier($tokenId);
|
||||
|
||||
if (!$accessToken->id) {
|
||||
if (!$accessToken->id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!$accessToken->revoked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_oauthserver
|
||||
*
|
||||
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
|
||||
* @license MIT; see LICENSE.txt
|
||||
**/
|
||||
|
||||
namespace Webmasterskaya\Component\OauthServer\Site\Repository;
|
||||
|
||||
use League\OAuth2\Server\Entities\AuthCodeEntityInterface;
|
||||
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
|
||||
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
|
||||
use Wamania\Snowball\NotFoundException;
|
||||
use Webmasterskaya\Component\OauthServer\Administrator\Model\AuthCodeModel;
|
||||
use Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel;
|
||||
use Webmasterskaya\Component\OauthServer\Site\Entity\AuthCode;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class AuthCodeRepository implements AuthCodeRepositoryInterface
|
||||
{
|
||||
private AuthCodeModel $authCodeModel;
|
||||
@ -17,14 +25,15 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface
|
||||
private ClientModel $clientModel;
|
||||
|
||||
/**
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\AuthCodeModel $authCodeModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel $clientModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\AuthCodeModel $authCodeModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel $clientModel
|
||||
*
|
||||
* @since version
|
||||
*/
|
||||
public function __construct(AuthCodeModel $authCodeModel, ClientModel $clientModel)
|
||||
{
|
||||
$this->authCodeModel = $authCodeModel;
|
||||
$this->clientModel = $clientModel;
|
||||
$this->clientModel = $clientModel;
|
||||
}
|
||||
|
||||
public function getNewAuthCode(): AuthCode
|
||||
@ -35,17 +44,22 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface
|
||||
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity)
|
||||
{
|
||||
$found = false;
|
||||
try {
|
||||
try
|
||||
{
|
||||
$authCode = $this->authCodeModel->getItemByIdentifier($authCodeEntity->getIdentifier());
|
||||
|
||||
if ($authCode->id > 0) {
|
||||
if ($authCode->id > 0)
|
||||
{
|
||||
$found = true;
|
||||
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
if ($found)
|
||||
{
|
||||
throw UniqueTokenIdentifierConstraintViolationException::create();
|
||||
}
|
||||
|
||||
@ -68,10 +82,11 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface
|
||||
{
|
||||
$authCode = $this->authCodeModel->getItemByIdentifier($codeId);
|
||||
|
||||
if (empty($authCode->id)) {
|
||||
if (empty($authCode->id))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!$authCode->revoked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_oauthserver
|
||||
*
|
||||
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
|
||||
* @license MIT; see LICENSE.txt
|
||||
**/
|
||||
|
||||
namespace Webmasterskaya\Component\OauthServer\Site\Repository;
|
||||
|
||||
@ -9,6 +16,8 @@ use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||
use Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel;
|
||||
use Webmasterskaya\Component\OauthServer\Site\Entity\Client;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class ClientRepository implements ClientRepositoryInterface
|
||||
{
|
||||
private ClientModel $clientModel;
|
||||
@ -20,6 +29,7 @@ class ClientRepository implements ClientRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param $clientIdentifier
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\ClientEntityInterface|null
|
||||
* @throws \Exception
|
||||
* @since version
|
||||
@ -28,7 +38,8 @@ class ClientRepository implements ClientRepositoryInterface
|
||||
{
|
||||
$item = $this->clientModel->getItemByIdentifier($clientIdentifier);
|
||||
|
||||
if (empty($item->id)) {
|
||||
if (empty($item->id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -39,19 +50,23 @@ class ClientRepository implements ClientRepositoryInterface
|
||||
{
|
||||
$item = $this->clientModel->getItemByIdentifier($clientIdentifier);
|
||||
|
||||
if (empty($item->id)) {
|
||||
if (empty($item->id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$item->active) {
|
||||
if (!$item->active)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->isGrantSupported($item, $grantType)) {
|
||||
if (!$this->isGrantSupported($item, $grantType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!!$item->public || hash_equals((string)$item->secret, (string)$clientSecret)) {
|
||||
if (!!$item->public || hash_equals((string) $item->secret, (string) $clientSecret))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -63,25 +78,27 @@ class ClientRepository implements ClientRepositoryInterface
|
||||
$clientEntity = new Client();
|
||||
$clientEntity->setName($client->name);
|
||||
$clientEntity->setIdentifier($client->identifier);
|
||||
$clientEntity->setRedirectUri(ArrayHelper::getColumn((array)$client->redirect_uris, 'uri'));
|
||||
$clientEntity->setRedirectUri(ArrayHelper::getColumn((array) $client->redirect_uris, 'uri'));
|
||||
$clientEntity->setConfidential(!$client->public);
|
||||
$clientEntity->setAllowPlainTextPkce((bool)$client->allow_plain_text_pkce);
|
||||
$clientEntity->setAllowPlainTextPkce((bool) $client->allow_plain_text_pkce);
|
||||
|
||||
return $clientEntity;
|
||||
}
|
||||
|
||||
private function isGrantSupported(\stdClass|CMSObject $client, ?string $grant): bool
|
||||
{
|
||||
if (null === $grant) {
|
||||
if (null === $grant)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$grants = array_map('strval', (array)$client->grants);
|
||||
$grants = array_map('strval', (array) $client->grants);
|
||||
|
||||
if (empty($grants)) {
|
||||
if (empty($grants))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return \in_array($grant, $grants);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_oauthserver
|
||||
*
|
||||
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
|
||||
* @license MIT; see LICENSE.txt
|
||||
**/
|
||||
|
||||
namespace Webmasterskaya\Component\OauthServer\Site\Repository;
|
||||
|
||||
@ -9,6 +16,8 @@ use Webmasterskaya\Component\OauthServer\Administrator\Model\AccessTokenModel;
|
||||
use Webmasterskaya\Component\OauthServer\Administrator\Model\RefreshTokenModel;
|
||||
use Webmasterskaya\Component\OauthServer\Site\Entity\RefreshToken;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class RefreshTokenRepository implements RefreshTokenRepositoryInterface
|
||||
{
|
||||
|
||||
@ -17,14 +26,15 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
|
||||
private AccessTokenModel $accessTokenModel;
|
||||
|
||||
/**
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\RefreshTokenModel $refreshTokenModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\AccessTokenModel $accessTokenModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\RefreshTokenModel $refreshTokenModel
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Model\AccessTokenModel $accessTokenModel
|
||||
*
|
||||
* @since version
|
||||
*/
|
||||
public function __construct(RefreshTokenModel $refreshTokenModel, AccessTokenModel $accessTokenModel)
|
||||
{
|
||||
$this->refreshTokenModel = $refreshTokenModel;
|
||||
$this->accessTokenModel = $accessTokenModel;
|
||||
$this->accessTokenModel = $accessTokenModel;
|
||||
}
|
||||
|
||||
|
||||
@ -36,16 +46,21 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
|
||||
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity)
|
||||
{
|
||||
$found = false;
|
||||
try {
|
||||
try
|
||||
{
|
||||
$refreshToken = $this->refreshTokenModel->getItemByIdentifier($refreshTokenEntity->getIdentifier());
|
||||
|
||||
if ($refreshToken->id > 0) {
|
||||
if ($refreshToken->id > 0)
|
||||
{
|
||||
$found = true;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
if ($found)
|
||||
{
|
||||
throw UniqueTokenIdentifierConstraintViolationException::create();
|
||||
}
|
||||
|
||||
@ -68,10 +83,11 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
|
||||
{
|
||||
$refreshToken = $this->refreshTokenModel->getItemByIdentifier($tokenId);
|
||||
|
||||
if (empty($refreshToken->id)) {
|
||||
if (empty($refreshToken->id))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!$refreshToken->revoked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_oauthserver
|
||||
*
|
||||
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
|
||||
* @license MIT; see LICENSE.txt
|
||||
**/
|
||||
|
||||
namespace Webmasterskaya\Component\OauthServer\Site\Repository;
|
||||
|
||||
@ -12,6 +19,8 @@ use Webmasterskaya\Component\OauthServer\Administrator\Event\Scope\ScopeResolveE
|
||||
use Webmasterskaya\Component\OauthServer\Administrator\Model\ClientModel;
|
||||
use Webmasterskaya\Component\OauthServer\Site\Entity\Scope;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class ScopeRepository implements ScopeRepositoryInterface, DispatcherAwareInterface
|
||||
{
|
||||
use DispatcherAwareTrait;
|
||||
@ -27,7 +36,8 @@ class ScopeRepository implements ScopeRepositoryInterface, DispatcherAwareInterf
|
||||
{
|
||||
$defined = ['userinfo', 'email'];
|
||||
|
||||
if (!in_array($identifier, $defined)) {
|
||||
if (!in_array($identifier, $defined))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -38,10 +48,11 @@ class ScopeRepository implements ScopeRepositoryInterface, DispatcherAwareInterf
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Scope[] $scopes
|
||||
* @param $grantType
|
||||
* @param \League\OAuth2\Server\Entities\ClientEntityInterface $clientEntity
|
||||
* @param null $userIdentifier
|
||||
* @param Scope[] $scopes
|
||||
* @param $grantType
|
||||
* @param \League\OAuth2\Server\Entities\ClientEntityInterface $clientEntity
|
||||
* @param null $userIdentifier
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
* @since version
|
||||
@ -67,8 +78,9 @@ class ScopeRepository implements ScopeRepositoryInterface, DispatcherAwareInterf
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $client
|
||||
* @param array $requestedScopes
|
||||
* @param object $client
|
||||
* @param array $requestedScopes
|
||||
*
|
||||
* @return array
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
* @since version
|
||||
@ -77,26 +89,31 @@ class ScopeRepository implements ScopeRepositoryInterface, DispatcherAwareInterf
|
||||
{
|
||||
$clientScopes = $client->scopes;
|
||||
|
||||
if (empty($clientScopes)) {
|
||||
if (empty($clientScopes))
|
||||
{
|
||||
return $requestedScopes;
|
||||
}
|
||||
|
||||
$clientScopes = array_map(function ($item) {
|
||||
$scope = new Scope();
|
||||
$scope->setIdentifier((string)$item);
|
||||
$scope->setIdentifier((string) $item);
|
||||
|
||||
return $scope;
|
||||
}, $clientScopes);
|
||||
|
||||
if (empty($requestedScopes)) {
|
||||
if (empty($requestedScopes))
|
||||
{
|
||||
return $clientScopes;
|
||||
}
|
||||
|
||||
$finalizedScopes = [];
|
||||
$finalizedScopes = [];
|
||||
$clientScopesAsStrings = array_map('strval', $clientScopes);
|
||||
|
||||
foreach ($requestedScopes as $requestedScope) {
|
||||
$requestedScopeAsString = (string)$requestedScope;
|
||||
if (!\in_array($requestedScopeAsString, $clientScopesAsStrings, true)) {
|
||||
foreach ($requestedScopes as $requestedScope)
|
||||
{
|
||||
$requestedScopeAsString = (string) $requestedScope;
|
||||
if (!\in_array($requestedScopeAsString, $clientScopesAsStrings, true))
|
||||
{
|
||||
throw OAuthServerException::invalidScope($requestedScopeAsString);
|
||||
}
|
||||
|
||||
@ -105,4 +122,4 @@ class ScopeRepository implements ScopeRepositoryInterface, DispatcherAwareInterf
|
||||
|
||||
return $finalizedScopes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user