filsh / yii2-oauth2-server

A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php)
MIT License
332 stars 167 forks source link

access token 404 #50

Closed anek77713 closed 4 years ago

anek77713 commented 9 years ago

version 2.0.1 installs - bshaffer/oauth2-server-php (v1.7.1) and in yii2 advanced template I get a 404 error when trying to generate an access token

2015-09-07 13:10:59 [127.0.0.1][-][-][error][yii\web\HttpException:404] exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "oauth2/default/token".' in /home/user/project/devel.local/vendor/yiisoft/yii2/base/Module.php:461 Stack trace:

0 /home/user/project/devel.local/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('oauth2/default/...', Array)

1 /home/user/project/devel.local/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))

2 /home/user/project/devel.local/api/www/index.php(17): yii\base\Application->run()

3 {main}

Next exception 'yii\web\NotFoundHttpException' with message 'Page not found.' in /home/user/project/devel.local/vendor/yiisoft/yii2/web/Application.php:96 Stack trace:

0 /home/user/project/devel.local/vendor/yiisoft/yii2/base/Application.php(375): yii\

my bad composer.json composer config:

"minimum-stability": "stable",
"require": {
    "php": ">=5.4.0",
    "yiisoft/yii2": ">=2.0.6",
    "yiisoft/yii2-bootstrap": "*",
    "yiisoft/yii2-swiftmailer": "*",
    "dektrium/yii2-user": "0.9.*@dev",
    "dektrium/yii2-rbac": "dev-master",
    "filsh/yii2-oauth2-server": "~2.0.1"
},

everything works fine with composer.json:

"minimum-stability": "stable",
"require": {
    "php": ">=5.4.0",
    "yiisoft/yii2": ">=2.0.6",
    "yiisoft/yii2-bootstrap": "*",
    "yiisoft/yii2-swiftmailer": "*",
    "dektrium/yii2-user": "0.9.*@dev",
    "dektrium/yii2-rbac": "dev-master",
    "filsh/yii2-oauth2-server": "dev-master"
},

When a new stable version is released?

Patroklo commented 9 years ago

Hi, version 2.0.1 it's not very stable in my opinion, you can use dev-master, I have made it work better.

About your problem, in 2.0.1 the controller it's called "RestController", while in dev-master it's called "DefaultController", so, recheck the url rules in your system to call rest/token/blah instead of default/token/blah. This should work.

tino415 commented 9 years ago

I have same problem but changing for "dev-master" was not working,

    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.6",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "filsh/yii2-oauth2-server": "dev-master"
    },

main.php config

'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'showScriptName' => false,
            'enablePrettyUrl' => true,
            'rules' => [
                'POST oauth2/<action: \w+>' => 'oauth2/default/<action>',
            ],
        ],

and module

'modules' => [
        'oauth2' => [
            'class' => 'filsh\yii2\oauth2server\Module',
            'options' => [
                'token_param_name' => 'accessToken',
                'access_lifetime' => 3600 * 24,
            ],
            'storageMap' => [
                'user_credentials' => 'common\models\User',
            ],
            'grantTypes' => [
                'user_credentials' => [
                    'class' => 'OAuth2\GrantType\UserCredentials',
                ],
                'refresh_token' => [
                    'class' => 'OAuth2\GrantType\RefreshToken',
                    'always_issue_new_refresh_token' => true
                ]
            ]
        ]
],
varp commented 4 years ago

Fixed in v2.1.0. Also the master brach now is the current development branch