mirror of
https://github.com/elyby/accounts.git
synced 2025-02-23 19:27:34 +05:30
Генерируемые AccessTokens заменены на UUID значения
This commit is contained in:
parent
7ea7c5245f
commit
eb1a3703cf
@ -7,7 +7,10 @@ use common\components\oauth\Storage\Yii2\AccessTokenStorage;
|
|||||||
use common\components\oauth\Storage\Yii2\ClientStorage;
|
use common\components\oauth\Storage\Yii2\ClientStorage;
|
||||||
use common\components\oauth\Storage\Yii2\ScopeStorage;
|
use common\components\oauth\Storage\Yii2\ScopeStorage;
|
||||||
use common\components\oauth\Storage\Yii2\SessionStorage;
|
use common\components\oauth\Storage\Yii2\SessionStorage;
|
||||||
|
use common\components\oauth\Util\KeyAlgorithm\UuidAlgorithm;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
use League\OAuth2\Server\Grant;
|
||||||
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
use yii\base\InvalidConfigException;
|
use yii\base\InvalidConfigException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,10 +32,10 @@ class Component extends \yii\base\Component {
|
|||||||
* @var array grant type => class
|
* @var array grant type => class
|
||||||
*/
|
*/
|
||||||
public $grantMap = [
|
public $grantMap = [
|
||||||
'authorization_code' => 'League\OAuth2\Server\Grant\AuthCodeGrant',
|
'authorization_code' => Grant\AuthCodeGrant::class,
|
||||||
'client_credentials' => 'League\OAuth2\Server\Grant\ClientCredentialsGrant',
|
'client_credentials' => Grant\ClientCredentialsGrant::class,
|
||||||
'password' => 'League\OAuth2\Server\Grant\PasswordGrant',
|
'password' => Grant\PasswordGrant::class,
|
||||||
'refresh_token' => 'League\OAuth2\Server\Grant\RefreshTokenGrant'
|
'refresh_token' => Grant\RefreshTokenGrant::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getAuthServer() {
|
public function getAuthServer() {
|
||||||
@ -57,6 +60,8 @@ class Component extends \yii\base\Component {
|
|||||||
$grant = new $this->grantMap[$grantType]();
|
$grant = new $this->grantMap[$grantType]();
|
||||||
$this->_authServer->addGrantType($grant);
|
$this->_authServer->addGrantType($grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SecureKey::setAlgorithm(new UuidAlgorithm());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_authServer;
|
return $this->_authServer;
|
||||||
|
17
common/components/oauth/Util/KeyAlgorithm/UuidAlgorithm.php
Normal file
17
common/components/oauth/Util/KeyAlgorithm/UuidAlgorithm.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace common\components\oauth\Util\KeyAlgorithm;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Util\KeyAlgorithm\DefaultAlgorithm;
|
||||||
|
use League\OAuth2\Server\Util\KeyAlgorithm\KeyAlgorithmInterface;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
|
||||||
|
class UuidAlgorithm extends DefaultAlgorithm implements KeyAlgorithmInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function generate($len = 40) : string {
|
||||||
|
return Uuid::uuid5(Uuid::NAMESPACE_DNS, parent::generate($len))->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,7 +17,7 @@ class OauthSteps extends \tests\codeception\api\FunctionalTester {
|
|||||||
], ['accept' => true]);
|
], ['accept' => true]);
|
||||||
$this->canSeeResponseJsonMatchesJsonPath('$.redirectUri');
|
$this->canSeeResponseJsonMatchesJsonPath('$.redirectUri');
|
||||||
$response = json_decode($this->grabResponse(), true);
|
$response = json_decode($this->grabResponse(), true);
|
||||||
preg_match('/code=(\w+)/', $response['redirectUri'], $matches);
|
preg_match('/code=([\w-]+)/', $response['redirectUri'], $matches);
|
||||||
|
|
||||||
return $matches[1];
|
return $matches[1];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user