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-02-14 23:20:10 +05:30
|
|
|
use League\OAuth2\Server\AuthorizationServer;
|
2017-09-19 22:36:16 +05:30
|
|
|
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
|
|
|
use League\OAuth2\Server\Storage\SessionInterface;
|
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-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_authServer;
|
|
|
|
}
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function getAccessTokenStorage(): AccessTokenInterface {
|
|
|
|
return $this->getAuthServer()->getAccessTokenStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRefreshTokenStorage(): RefreshTokenInterface {
|
|
|
|
return $this->getAuthServer()->getRefreshTokenStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSessionStorage(): SessionInterface {
|
|
|
|
return $this->getAuthServer()->getSessionStorage();
|
|
|
|
}
|
|
|
|
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|