2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
2016-11-27 03:13:42 +05:30
|
|
|
namespace api\components\OAuth2;
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2017-06-17 23:35:36 +05:30
|
|
|
use api\components\OAuth2\Storage;
|
2016-11-27 03:13:42 +05:30
|
|
|
use api\components\OAuth2\Utils\KeyAlgorithm\UuidAlgorithm;
|
2016-02-14 23:20:10 +05:30
|
|
|
use League\OAuth2\Server\AuthorizationServer;
|
2016-06-18 19:08:15 +05:30
|
|
|
use League\OAuth2\Server\Util\SecureKey;
|
2017-06-17 23:35:36 +05:30
|
|
|
use yii\base\Component as BaseComponent;
|
2016-02-14 23:20:10 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* @property AuthorizationServer $authServer
|
|
|
|
*/
|
2017-06-17 23:35:36 +05:30
|
|
|
class Component extends BaseComponent {
|
2016-02-14 23:20:10 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AuthorizationServer
|
|
|
|
*/
|
|
|
|
private $_authServer;
|
|
|
|
|
2017-06-17 23:35:36 +05:30
|
|
|
public function getAuthServer(): AuthorizationServer {
|
2016-02-14 23:20:10 +05:30
|
|
|
if ($this->_authServer === null) {
|
|
|
|
$authServer = new AuthorizationServer();
|
2017-06-17 23:35:36 +05:30
|
|
|
$authServer->setAccessTokenStorage(new Storage\AccessTokenStorage());
|
|
|
|
$authServer->setClientStorage(new Storage\ClientStorage());
|
|
|
|
$authServer->setScopeStorage(new Storage\ScopeStorage());
|
|
|
|
$authServer->setSessionStorage(new Storage\SessionStorage());
|
|
|
|
$authServer->setAuthCodeStorage(new Storage\AuthCodeStorage());
|
|
|
|
$authServer->setRefreshTokenStorage(new Storage\RefreshTokenStorage());
|
2016-11-27 03:13:42 +05:30
|
|
|
$authServer->setScopeDelimiter(',');
|
2017-03-07 21:39:41 +05:30
|
|
|
$authServer->setAccessTokenTTL(86400); // 1d
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2017-06-17 23:35:36 +05:30
|
|
|
$authServer->addGrantType(new Grants\AuthCodeGrant());
|
|
|
|
$authServer->addGrantType(new Grants\RefreshTokenGrant());
|
|
|
|
$authServer->addGrantType(new Grants\ClientCredentialsGrant());
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2017-06-17 23:35:36 +05:30
|
|
|
$this->_authServer = $authServer;
|
2016-06-18 19:08:15 +05:30
|
|
|
|
|
|
|
SecureKey::setAlgorithm(new UuidAlgorithm());
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_authServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|