mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Translate all code comments from Russian to English [skip ci]
This commit is contained in:
@@ -196,7 +196,7 @@ class AuthCodeGrant extends AbstractGrant {
|
||||
$this->server->getTokenType()->setParam('access_token', $accessToken->getId());
|
||||
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
|
||||
|
||||
// Выдаём refresh_token, если запрошен offline_access
|
||||
// Set refresh_token param only in case when offline_access requested
|
||||
if (isset($accessToken->getScopes()[ScopeStorage::OFFLINE_ACCESS])) {
|
||||
/** @var RefreshTokenGrant $refreshTokenGrant */
|
||||
$refreshTokenGrant = $this->server->getGrantType('refresh_token');
|
||||
@@ -222,8 +222,9 @@ class AuthCodeGrant extends AbstractGrant {
|
||||
}
|
||||
|
||||
/**
|
||||
* По стандарту OAuth2 scopes должны разделяться пробелом, а не запятой. Косяк.
|
||||
* Так что оборачиваем функцию разбора скоупов, заменяя запятые на пробелы.
|
||||
* In the earlier versions of Accounts Ely.by backend we had a comma-separated scopes
|
||||
* list, while by OAuth2 standard it they should be separated by a space. Shit happens :)
|
||||
* So override scopes validation function to reformat passed value.
|
||||
*
|
||||
* @param string $scopeParam
|
||||
* @param BaseClientEntity $client
|
||||
|
@@ -69,8 +69,9 @@ class ClientCredentialsGrant extends AbstractGrant {
|
||||
}
|
||||
|
||||
/**
|
||||
* По стандарту OAuth2 scopes должны разделяться пробелом, а не запятой. Косяк.
|
||||
* Так что оборачиваем функцию разбора скоупов, заменяя запятые на пробелы.
|
||||
* In the earlier versions of Accounts Ely.by backend we had a comma-separated scopes
|
||||
* list, while by OAuth2 standard it they should be separated by a space. Shit happens :)
|
||||
* So override scopes validation function to reformat passed value.
|
||||
*
|
||||
* @param string $scopeParam
|
||||
* @param BaseClientEntity $client
|
||||
|
@@ -48,8 +48,9 @@ class RefreshTokenGrant extends AbstractGrant {
|
||||
}
|
||||
|
||||
/**
|
||||
* По стандарту OAuth2 scopes должны разделяться пробелом, а не запятой. Косяк.
|
||||
* Так что оборачиваем функцию разбора скоупов, заменяя запятые на пробелы.
|
||||
* In the earlier versions of Accounts Ely.by backend we had a comma-separated scopes
|
||||
* list, while by OAuth2 standard it they should be separated by a space. Shit happens :)
|
||||
* So override scopes validation function to reformat passed value.
|
||||
*
|
||||
* @param string $scopeParam
|
||||
* @param BaseClientEntity $client
|
||||
@@ -62,9 +63,9 @@ class RefreshTokenGrant extends AbstractGrant {
|
||||
}
|
||||
|
||||
/**
|
||||
* Метод таки пришлось переписать по той причине, что нынче мы храним access_token в redis с expire значением,
|
||||
* так что он может банально несуществовать на тот момент, когда к нему через refresh_token попытаются обратиться.
|
||||
* Поэтому мы расширили логику RefreshTokenEntity и она теперь знает о сессии, в рамках которой была создана
|
||||
* The method has been overridden because we stores access_tokens in Redis with expire value,
|
||||
* so they might not exists at the moment, when it will be requested via refresh_token.
|
||||
* That's why we extends RefreshTokenEntity to give it knowledge about related session.
|
||||
*
|
||||
* @inheritdoc
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthException
|
||||
|
@@ -27,16 +27,12 @@ class ClientStorage extends AbstractStorage implements ClientInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: нужно учитывать тип приложения
|
||||
/*
|
||||
* Для приложений типа "настольный" redirect_uri необязателем - он должен быть по умолчанию равен
|
||||
* статичному редиректу на страницу сайта
|
||||
* А для приложений типа "сайт" редирект должен быть всегда.
|
||||
* Короче это нужно учесть
|
||||
*/
|
||||
// TODO: should check application type
|
||||
// For "desktop" app type redirect_uri is not required and should be by default set
|
||||
// to the static redirect, but for "site" it's required always.
|
||||
if ($redirectUri !== null) {
|
||||
if (in_array($redirectUri, [self::REDIRECT_STATIC_PAGE, self::REDIRECT_STATIC_PAGE_WITH_CODE], true)) {
|
||||
// Тут, наверное, нужно проверить тип приложения
|
||||
// I think we should check the type of application here
|
||||
} else {
|
||||
if (!StringHelper::startsWith($redirectUri, $model->redirect_uri, false)) {
|
||||
return null;
|
||||
|
@@ -39,8 +39,8 @@ class ScopeStorage extends AbstractStorage implements ScopeInterface {
|
||||
|
||||
/**
|
||||
* @param string $scope
|
||||
* @param string $grantType передаётся, если запрос поступает из grant. В этом случае нужно отфильтровать
|
||||
* только те права, которые можно получить на этом grant.
|
||||
* @param string $grantType is passed on if called from the grant.
|
||||
* In this case, you only need to filter out the rights that you can get on this grant.
|
||||
* @param string $clientId
|
||||
*
|
||||
* @return ScopeEntity|null
|
||||
|
@@ -52,7 +52,7 @@ class SessionStorage extends AbstractStorage implements SessionInterface {
|
||||
->andWhere([
|
||||
'client_id' => $clientId,
|
||||
'owner_type' => $ownerType,
|
||||
'owner_id' => (string)$ownerId, // Переводим в строку, чтобы работали индексы, т.к. поле varchar
|
||||
'owner_id' => (string)$ownerId, // Casts as a string to make the indexes work, because the varchar field
|
||||
])->scalar();
|
||||
|
||||
if ($sessionId === false) {
|
||||
|
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\components\OAuth2\Utils;
|
||||
|
||||
class Scopes {
|
||||
|
||||
/**
|
||||
* По стандарту OAuth2 scopes должны разделяться пробелом, а не запятой. Косяк.
|
||||
* Так что оборачиваем функцию разбора скоупов, заменяя запятые на пробелы.
|
||||
* Заодно учитываем возможность передать скоупы в виде массива.
|
||||
* In the earlier versions of Accounts Ely.by backend we had a comma-separated scopes
|
||||
* list, while by OAuth2 standard it they should be separated by a space. Shit happens :)
|
||||
* So override scopes validation function to reformat passed value.
|
||||
*
|
||||
* @param string|array $scopes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function format($scopes): string {
|
||||
@@ -21,7 +22,6 @@ class Scopes {
|
||||
return implode(' ', $scopes);
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncompatibleReturnTypeInspection */
|
||||
return str_replace(',', ' ', $scopes);
|
||||
}
|
||||
|
||||
|
@@ -92,8 +92,8 @@ class Component extends YiiUserComponent {
|
||||
$token->addClaim(new Claim\JwtId($session->id));
|
||||
} else {
|
||||
$session = null;
|
||||
// Если мы не сохраняем сессию, то токен должен жить подольше,
|
||||
// чтобы не прогорала сессия во время работы с аккаунтом
|
||||
// If we don't remember a session, the token should live longer
|
||||
// so that the session doesn't end while working with the account
|
||||
$token->addClaim(new Claim\Expiration((new DateTime())->add(new DateInterval($this->sessionTimeout))));
|
||||
}
|
||||
|
||||
@@ -125,8 +125,8 @@ class Component extends YiiUserComponent {
|
||||
|
||||
/**
|
||||
* @param string $jwtString
|
||||
* @return Token распаршенный токен
|
||||
* @throws VerificationException если один из Claims не пройдёт проверку
|
||||
* @return Token
|
||||
* @throws VerificationException in case when some Claim not pass the validation
|
||||
*/
|
||||
public function parseToken(string $jwtString): Token {
|
||||
$token = &self::$parsedTokensCache[$jwtString];
|
||||
@@ -149,13 +149,13 @@ class Component extends YiiUserComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Метод находит AccountSession модель, относительно которой был выдан текущий JWT токен.
|
||||
* В случае, если на пути поиска встретится ошибка, будет возвращено значение null. Возможные кейсы:
|
||||
* - Юзер не авторизован
|
||||
* - Почему-то нет заголовка с токеном
|
||||
* - Во время проверки токена возникла ошибка, что привело к исключению
|
||||
* - В токене не найдено ключа сессии. Такое возможно, если юзер выбрал "не запоминать меня"
|
||||
* или просто старые токены, без поддержки сохранения используемой сессии
|
||||
* The method searches AccountSession model, which one has been used to create current JWT token.
|
||||
* null will be returned in case when any of the following situations occurred:
|
||||
* - The user isn't authorized
|
||||
* - There is no header with a token
|
||||
* - Token validation isn't passed and some exception has been thrown
|
||||
* - No session key found in the token. This is possible if the user chose not to remember me
|
||||
* or just some old tokens, without the support of saving the used session
|
||||
*
|
||||
* @return AccountSession|null
|
||||
*/
|
||||
|
@@ -17,17 +17,17 @@ interface IdentityInterface extends \yii\web\IdentityInterface {
|
||||
public static function findIdentityByAccessToken($token, $type = null): IdentityInterface;
|
||||
|
||||
/**
|
||||
* Этот метод используется для получения токена, к которому привязаны права.
|
||||
* У нас права привязываются к токенам, так что возвращаем именно его id.
|
||||
* This method is used to obtain a token to which scopes are attached.
|
||||
* Our permissions are attached to tokens itself, so we return its id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string;
|
||||
|
||||
/**
|
||||
* Метод возвращает аккаунт, который привязан к текущему токену.
|
||||
* Но не исключено, что токен был выдан и без привязки к аккаунту, так что
|
||||
* следует это учитывать.
|
||||
* The method returns an account that is attached to the current token.
|
||||
* But it's possible that the token was issued without binding to the account,
|
||||
* so you should handle it.
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
|
Reference in New Issue
Block a user