pgaultier / yii2-oauth2

OAuth2 wrapper for Yii2 applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to config a console command?

dixonsatit opened this issue · comments

i want to config a console comnad in oauth2. i try this config. don't work.

return [
    'id' => 'app-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'console\controllers',
    'modules' => [
        'oauth2' => [
            'class' => 'sweelix\oauth2\server\Module'
        ],
    ]
...
]

or ?

   'controllerMap'       => [
         'client' => 'sweelix\oauth2\server\commands\ClientController',
         'key' => 'sweelix\oauth2\server\commands\KeyController',
         'scope' => 'sweelix\oauth2\server\commands\ScopeController'
     ],

error.

./yii client/create --userId=1
Exception 'yii\di\NotInstantiableException' with message 'Can not instantiate sweelix\oauth2\server\interfaces\ClientModelInterface.'

in /var/www/html/vendor/yiisoft/yii2/di/Container.php:370

Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/di/Container.php(154): yii\di\Container->build('sweelix\\oauth2\\...', Array, Array)
#1 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(340): yii\di\Container->get('sweelix\\oauth2\\...', Array)
#2 /var/www/html/vendor/sweelix/yii2-oauth2-server/src/commands/ClientController.php(66): yii\BaseYii::createObject('sweelix\\oauth2\\...')
#3 [internal function]: sweelix\oauth2\server\commands\ClientController->actionCreate()
#4 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#6 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(128): yii\base\Controller->runAction('create', Array)
#7 /var/www/html/vendor/yiisoft/yii2/base/Module.php(454): yii\console\Controller->runAction('create', Array)
#8 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('client/create', Array)
#9 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('client/create', Array)
#10 /var/www/html/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))
#11 /var/www/html/yii(30): yii\base\Application->run()
#12 {main}

thank you.

i try this config it work.

return [
    'id' => 'app-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'console\controllers',
    'modules' => [
        'oauth2' => [
            'class' => 'sweelix\oauth2\server\Module',
                'controllerMap' => [
                    'client' => 'sweelix\oauth2\server\commands\ClientController',
                    'key' => 'sweelix\oauth2\server\commands\KeyController',
                    'scope' => 'sweelix\oauth2\server\commands\ScopeController'
            ],
        ],
    ],

screen shot 2016-12-12 at 09 24 43

i try this command. it error.

./yii oauth2/client/create --name=test --redirectUri=http://app-frontend.dev:9090 --userId=1

screen shot 2016-12-12 at 09 27 32

Hello,

you shouldn't have to config anything for console command.
Everything is automagically added to the config if you have added the module to the console conf and if the module is bootstrapped
image

Please check the bootstrap part and the module part

Once done, when you type ;

./yii 

you sould see :
image

In order to use the client creation (for example), you should do :

./yii oauth2:client/create --userId=1