From e05fff97252f9e067cf0eae276ea36e9e87ae3e2 Mon Sep 17 00:00:00 2001 From: Maliy Igor Date: Fri, 19 Jun 2015 15:30:06 +0300 Subject: [PATCH] v2.0.0 --- Bootstrap.php | 2 ++ Module.php | 28 +++++++++---------- Server.php | 6 ++++ ...faultController.php => RestController.php} | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) rename controllers/{DefaultController.php => RestController.php} (91%) diff --git a/Bootstrap.php b/Bootstrap.php index bd65763..b9b15db 100644 --- a/Bootstrap.php +++ b/Bootstrap.php @@ -2,6 +2,8 @@ namespace filsh\yii2\oauth2server; +use yii\web\GroupUrlRule; + class Bootstrap implements \yii\base\BootstrapInterface { /** diff --git a/Module.php b/Module.php index 87cfb3d..108ccb2 100755 --- a/Module.php +++ b/Module.php @@ -11,26 +11,20 @@ * ```php * 'oauth2' => [ * 'class' => 'filsh\yii2\oauth2server\Module', - * 'options' => [ - * 'token_param_name' => 'accessToken', - * 'access_lifetime' => 3600 - * ], + * 'tokenParamName' => 'accessToken', + * 'tokenAccessLifetime' => 3600 * 24, * 'storageMap' => [ - * 'user_credentials' => 'common\models\User' + * 'user_credentials' => 'common\models\User', * ], * 'grantTypes' => [ - * 'client_credentials' => [ - * 'class' => '\OAuth2\GrantType\ClientCredentials', - * 'allow_public_clients' => false - * ], * 'user_credentials' => [ - * 'class' => '\OAuth2\GrantType\UserCredentials' + * 'class' => 'OAuth2\GrantType\UserCredentials', * ], * 'refresh_token' => [ - * 'class' => '\OAuth2\GrantType\RefreshToken', + * 'class' => 'OAuth2\GrantType\RefreshToken', * 'always_issue_new_refresh_token' => true * ] - * ], + * ] * ] * ``` */ @@ -49,12 +43,18 @@ class Module extends \yii\base\Module public $storageMap = []; /** - * @var array GrantTypes map + * @var array GrantTypes collection */ public $grantTypes = []; + /** + * @var string name of access token parameter + */ public $tokenParamName; + /** + * @var type max access lifetime + */ public $tokenAccessLifetime; /** @@ -95,7 +95,7 @@ public function getServer() $instance = $reflection->newInstanceArgs($config); $grantTypes[$name] = $instance; } - + $server = \Yii::$container->get(Server::className(), [ $this, $storages, diff --git a/Server.php b/Server.php index 669d341..78e78ac 100644 --- a/Server.php +++ b/Server.php @@ -17,6 +17,12 @@ public function __construct(Module $module, $storage = array(), array $config = parent::__construct($storage, $config, $grantTypes, $responseTypes, $tokenType, $scopeUtil, $clientAssertionType); } + public function createAccessToken($clientId, $userId, $scope = null, $includeRefreshToken = true) + { + $accessToken = $this->getAccessTokenResponseType(); + return $accessToken->createAccessToken($clientId, $userId, $scope, $includeRefreshToken); + } + public function verifyResourceRequest(\OAuth2\RequestInterface $request = null, \OAuth2\ResponseInterface $response = null, $scope = null) { if($request === null) { diff --git a/controllers/DefaultController.php b/controllers/RestController.php similarity index 91% rename from controllers/DefaultController.php rename to controllers/RestController.php index 34bab9b..c9978b3 100755 --- a/controllers/DefaultController.php +++ b/controllers/RestController.php @@ -6,7 +6,7 @@ use yii\helpers\ArrayHelper; use filsh\yii2\oauth2server\filters\ErrorToExceptionFilter; -class DefaultController extends \yii\rest\Controller +class RestController extends \yii\rest\Controller { /** * @inheritdoc