mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Переводим пробелы (по стандарту OAuth2) в наш scopes delimiter.
This commit is contained in:
		@@ -2,6 +2,7 @@
 | 
				
			|||||||
namespace api\components\OAuth2\Grants;
 | 
					namespace api\components\OAuth2\Grants;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use api\components\OAuth2\Entities;
 | 
					use api\components\OAuth2\Entities;
 | 
				
			||||||
 | 
					use League\OAuth2\Server\Entity\ClientEntity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AuthCodeGrant extends \League\OAuth2\Server\Grant\AuthCodeGrant {
 | 
					class AuthCodeGrant extends \League\OAuth2\Server\Grant\AuthCodeGrant {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,4 +18,19 @@ class AuthCodeGrant extends \League\OAuth2\Server\Grant\AuthCodeGrant {
 | 
				
			|||||||
        return new Entities\SessionEntity($this->server);
 | 
					        return new Entities\SessionEntity($this->server);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * По стандарту OAuth2 scopes должны разделяться пробелом, а не запятой. Косяк.
 | 
				
			||||||
 | 
					     * Так что оборачиваем функцию разбора скоупов, заменяя пробелы на запятые.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param string       $scopeParam
 | 
				
			||||||
 | 
					     * @param ClientEntity $client
 | 
				
			||||||
 | 
					     * @param string $redirectUri
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return \League\OAuth2\Server\Entity\ScopeEntity[]
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null) {
 | 
				
			||||||
 | 
					        $scopes = str_replace(' ', $this->server->getScopeDelimiter(), $scopeParam);
 | 
				
			||||||
 | 
					        return parent::validateScopes($scopes, $client, $redirectUri);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@
 | 
				
			|||||||
namespace api\components\OAuth2\Grants;
 | 
					namespace api\components\OAuth2\Grants;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use api\components\OAuth2\Entities;
 | 
					use api\components\OAuth2\Entities;
 | 
				
			||||||
 | 
					use League\OAuth2\Server\Entity\ClientEntity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ClientCredentialsGrant extends \League\OAuth2\Server\Grant\ClientCredentialsGrant {
 | 
					class ClientCredentialsGrant extends \League\OAuth2\Server\Grant\ClientCredentialsGrant {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,4 +18,19 @@ class ClientCredentialsGrant extends \League\OAuth2\Server\Grant\ClientCredentia
 | 
				
			|||||||
        return new Entities\SessionEntity($this->server);
 | 
					        return new Entities\SessionEntity($this->server);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * По стандарту OAuth2 scopes должны разделяться пробелом, а не запятой. Косяк.
 | 
				
			||||||
 | 
					     * Так что оборачиваем функцию разбора скоупов, заменяя пробелы на запятые.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param string       $scopeParam
 | 
				
			||||||
 | 
					     * @param ClientEntity $client
 | 
				
			||||||
 | 
					     * @param string $redirectUri
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return \League\OAuth2\Server\Entity\ScopeEntity[]
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null) {
 | 
				
			||||||
 | 
					        $scopes = str_replace(' ', $this->server->getScopeDelimiter(), $scopeParam);
 | 
				
			||||||
 | 
					        return parent::validateScopes($scopes, $client, $redirectUri);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ namespace api\components\OAuth2\Grants;
 | 
				
			|||||||
use api\components\OAuth2\Entities;
 | 
					use api\components\OAuth2\Entities;
 | 
				
			||||||
use ErrorException;
 | 
					use ErrorException;
 | 
				
			||||||
use League\OAuth2\Server\Entity\ClientEntity as OriginalClientEntity;
 | 
					use League\OAuth2\Server\Entity\ClientEntity as OriginalClientEntity;
 | 
				
			||||||
 | 
					use League\OAuth2\Server\Entity\ClientEntity;
 | 
				
			||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity as OriginalRefreshTokenEntity;
 | 
					use League\OAuth2\Server\Entity\RefreshTokenEntity as OriginalRefreshTokenEntity;
 | 
				
			||||||
use League\OAuth2\Server\Event;
 | 
					use League\OAuth2\Server\Event;
 | 
				
			||||||
use League\OAuth2\Server\Exception;
 | 
					use League\OAuth2\Server\Exception;
 | 
				
			||||||
@@ -25,6 +26,21 @@ class RefreshTokenGrant extends \League\OAuth2\Server\Grant\RefreshTokenGrant {
 | 
				
			|||||||
        return new Entities\SessionEntity($this->server);
 | 
					        return new Entities\SessionEntity($this->server);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * По стандарту OAuth2 scopes должны разделяться пробелом, а не запятой. Косяк.
 | 
				
			||||||
 | 
					     * Так что оборачиваем функцию разбора скоупов, заменяя пробелы на запятые.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param string       $scopeParam
 | 
				
			||||||
 | 
					     * @param ClientEntity $client
 | 
				
			||||||
 | 
					     * @param string $redirectUri
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return \League\OAuth2\Server\Entity\ScopeEntity[]
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null) {
 | 
				
			||||||
 | 
					        $scopes = str_replace(' ', $this->server->getScopeDelimiter(), $scopeParam);
 | 
				
			||||||
 | 
					        return parent::validateScopes($scopes, $client, $redirectUri);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Метод таки пришлось переписать по той причине, что нынче мы храним access_token в redis с expire значением,
 | 
					     * Метод таки пришлось переписать по той причине, что нынче мы храним access_token в redis с expire значением,
 | 
				
			||||||
     * так что он может банально несуществовать на тот момент, когда к нему через refresh_token попытаются обратиться.
 | 
					     * так что он может банально несуществовать на тот момент, когда к нему через refresh_token попытаются обратиться.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user