mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implemented PHP-CS-Fixer support
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace api\components\OAuth2;
|
||||
|
||||
use api\components\OAuth2\Storage;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
||||
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
||||
|
@@ -9,11 +9,11 @@ class RefreshTokenEntity extends \League\OAuth2\Server\Entity\RefreshTokenEntity
|
||||
|
||||
private $sessionId;
|
||||
|
||||
public function isExpired() : bool {
|
||||
public function isExpired(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSession() : SessionEntity {
|
||||
public function getSession(): SessionEntity {
|
||||
if ($this->session instanceof SessionEntity) {
|
||||
return $this->session;
|
||||
}
|
||||
@@ -26,18 +26,18 @@ class RefreshTokenEntity extends \League\OAuth2\Server\Entity\RefreshTokenEntity
|
||||
return $sessionStorage->getById($this->sessionId);
|
||||
}
|
||||
|
||||
public function getSessionId() : int {
|
||||
public function getSessionId(): int {
|
||||
return $this->sessionId;
|
||||
}
|
||||
|
||||
public function setSession(OriginalSessionEntity $session) {
|
||||
public function setSession(OriginalSessionEntity $session): self {
|
||||
parent::setSession($session);
|
||||
$this->setSessionId($session->getId());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSessionId(int $sessionId) {
|
||||
public function setSessionId(int $sessionId): void {
|
||||
$this->sessionId = $sessionId;
|
||||
}
|
||||
|
||||
|
@@ -133,8 +133,10 @@ class AuthCodeGrant extends AbstractGrant {
|
||||
throw new Exception\InvalidRequestException('client_id');
|
||||
}
|
||||
|
||||
$clientSecret = $this->server->getRequest()->request->get('client_secret',
|
||||
$this->server->getRequest()->getPassword());
|
||||
$clientSecret = $this->server->getRequest()->request->get(
|
||||
'client_secret',
|
||||
$this->server->getRequest()->getPassword()
|
||||
);
|
||||
if ($clientSecret === null && $this->shouldRequireClientSecret()) {
|
||||
throw new Exception\InvalidRequestException('client_secret');
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ class AccessTokenStorage extends AbstractStorage implements AccessTokenInterface
|
||||
public function getScopes(OriginalAccessTokenEntity $token) {
|
||||
$scopes = $this->scopes($token->getId());
|
||||
$entities = [];
|
||||
foreach($scopes as $scope) {
|
||||
foreach ($scopes as $scope) {
|
||||
if ($this->server->getScopeStorage()->get($scope) !== null) {
|
||||
$entities[] = (new ScopeEntity($this->server))->hydrate(['id' => $scope]);
|
||||
}
|
||||
@@ -59,11 +59,11 @@ class AccessTokenStorage extends AbstractStorage implements AccessTokenInterface
|
||||
$this->scopes($token->getId())->delete();
|
||||
}
|
||||
|
||||
private function key(string $token) : Key {
|
||||
private function key(string $token): Key {
|
||||
return new Key($this->dataTable, $token);
|
||||
}
|
||||
|
||||
private function scopes(string $token) : Set {
|
||||
private function scopes(string $token): Set {
|
||||
return new Set($this->dataTable, $token, 'scopes');
|
||||
}
|
||||
|
||||
|
@@ -61,11 +61,11 @@ class AuthCodeStorage extends AbstractStorage implements AuthCodeInterface {
|
||||
$this->scopes($token->getId())->delete();
|
||||
}
|
||||
|
||||
private function key(string $token) : Key {
|
||||
private function key(string $token): Key {
|
||||
return new Key($this->dataTable, $token);
|
||||
}
|
||||
|
||||
private function scopes(string $token) : Set {
|
||||
private function scopes(string $token): Set {
|
||||
return new Set($this->dataTable, $token, 'scopes');
|
||||
}
|
||||
|
||||
|
@@ -11,8 +11,8 @@ use yii\helpers\StringHelper;
|
||||
|
||||
class ClientStorage extends AbstractStorage implements ClientInterface {
|
||||
|
||||
const REDIRECT_STATIC_PAGE = 'static_page';
|
||||
const REDIRECT_STATIC_PAGE_WITH_CODE = 'static_page_with_code';
|
||||
private const REDIRECT_STATIC_PAGE = 'static_page';
|
||||
private const REDIRECT_STATIC_PAGE_WITH_CODE = 'static_page_with_code';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -66,7 +66,7 @@ class ClientStorage extends AbstractStorage implements ClientInterface {
|
||||
return $this->hydrate($model);
|
||||
}
|
||||
|
||||
private function hydrate(OauthClient $model) : ClientEntity {
|
||||
private function hydrate(OauthClient $model): ClientEntity {
|
||||
$entity = new ClientEntity($this->server);
|
||||
$entity->setId($model->id);
|
||||
$entity->setName($model->name);
|
||||
|
@@ -51,12 +51,12 @@ class RefreshTokenStorage extends AbstractStorage implements RefreshTokenInterfa
|
||||
$this->sessionHash($token->getSessionId())->remove($token->getId());
|
||||
}
|
||||
|
||||
public function sessionHash(string $sessionId) : Set {
|
||||
public function sessionHash(string $sessionId): Set {
|
||||
$tableName = Yii::$app->db->getSchema()->getRawTableName(OauthSession::tableName());
|
||||
return new Set($tableName, $sessionId, 'refresh_tokens');
|
||||
}
|
||||
|
||||
private function key(string $token) : Key {
|
||||
private function key(string $token): Key {
|
||||
return new Key($this->dataTable, $token);
|
||||
}
|
||||
|
||||
|
@@ -76,7 +76,7 @@ class SessionStorage extends AbstractStorage implements SessionInterface {
|
||||
$this->getSessionModel($session->getId())->getScopes()->add($scope->getId());
|
||||
}
|
||||
|
||||
private function getSessionModel(string $sessionId) : OauthSession {
|
||||
private function getSessionModel(string $sessionId): OauthSession {
|
||||
$session = OauthSession::findOne($sessionId);
|
||||
if ($session === null) {
|
||||
throw new ErrorException('Cannot find oauth session');
|
||||
|
@@ -214,7 +214,7 @@ class Component extends YiiUserComponent {
|
||||
|
||||
protected function createToken(Account $account): Token {
|
||||
$token = new Token();
|
||||
foreach($this->getClaims($account) as $claim) {
|
||||
foreach ($this->getClaims($account) as $claim) {
|
||||
$token->addClaim($claim);
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,10 @@ class Identity implements IdentityInterface {
|
||||
*/
|
||||
private $_accessToken;
|
||||
|
||||
private function __construct(AccessTokenEntity $accessToken) {
|
||||
$this->_accessToken = $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @throws \yii\web\UnauthorizedHttpException
|
||||
@@ -73,10 +77,6 @@ class Identity implements IdentityInterface {
|
||||
throw new NotSupportedException('This method used for cookie auth, except we using Bearer auth');
|
||||
}
|
||||
|
||||
private function __construct(AccessTokenEntity $accessToken) {
|
||||
$this->_accessToken = $accessToken;
|
||||
}
|
||||
|
||||
private function getSession(): OauthSession {
|
||||
return OauthSession::findOne($this->_accessToken->getSessionId());
|
||||
}
|
||||
|
@@ -23,6 +23,11 @@ class JwtIdentity implements IdentityInterface {
|
||||
*/
|
||||
private $token;
|
||||
|
||||
private function __construct(string $rawToken, Token $token) {
|
||||
$this->rawToken = $rawToken;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public static function findIdentityByAccessToken($rawToken, $type = null): IdentityInterface {
|
||||
/** @var \api\components\User\Component $component */
|
||||
$component = Yii::$app->user;
|
||||
@@ -86,9 +91,4 @@ class JwtIdentity implements IdentityInterface {
|
||||
throw new NotSupportedException('This method used for cookie auth, except we using Bearer auth');
|
||||
}
|
||||
|
||||
private function __construct(string $rawToken, Token $token) {
|
||||
$this->rawToken = $rawToken;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ use Emarref\Jwt\Claim\AbstractClaim;
|
||||
|
||||
class ScopesClaim extends AbstractClaim {
|
||||
|
||||
const NAME = 'ely-scopes';
|
||||
public const NAME = 'ely-scopes';
|
||||
|
||||
/**
|
||||
* ScopesClaim constructor.
|
||||
|
@@ -21,7 +21,7 @@ class SubjectPrefixVerifier implements VerifierInterface {
|
||||
$subject = ($subjectClaim === null) ? null : $subjectClaim->getValue();
|
||||
|
||||
if (!StringHelper::startsWith($subject, $this->subjectPrefix)) {
|
||||
throw new InvalidSubjectException;
|
||||
throw new InvalidSubjectException();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user